How to select datasource and delegate in xcode 4.5? - xcode

I am c# asp.net developer and just a newbe in developing ios apps. I am trying some tutorials to build some uipickerview. But the most tutorials are using an xib file. My project is a storyboard project and dont have a xib file. So Iam wondering how I can connect my datasource and delegate from my uipickerview? In some toturials I see the "view controller scene" window in xcode, but I cannot find it in my xcode. So can somebody tell me what to do to show this "view controller scene" OR how to connect my uipickerview to the datasource and delegate?

The Storyboard is replacing the xib files and combines all your views into a single file for iPhone or iPad. To connect a picker view data source and delegate you can select the UIPickerView object in Interface Builder, go to the Connections Inspector (the menu with the arrow icon on the right) and there drag from the datasource to the view controller file owner.
Do the same for the delegate.
Then in the header file of that view controller you need to add the UIPickerViewDataSource and UIPickerViewDelegate protocols to the interface and in the implementation file implement the relevant methods.

Drag the delegates to the files owner in interface builder, you dont need a interface

Related

Linking storyboard view controller to its own viewcontroller.swift in Xcode 7.2

In the new Xcode 7.2 (iOS9), how do I add a viewcontroller.swift file and link it to a manually added view controller in the storyboard?
(This seems to be different than previous versions of Xcode where one would manually add a Cocoa Touch file after dragging a new view controller object in thestoryboard.)
Thank you.
It has always been the same for me but here are the steps that I follow.
Right click the file explorer on the left
Click Source->Next->Subclass UIViewController
Drag UIViewController into Interface Builder
Click the yellow circle to focus on the UIViewController
Click the Identity Inspector
Set the Custom Class to the name in your Swift File

Adding outlets to iPhone View

I am creating a custom iPhone View in MonoTouch through the interface builder in XCode (In monodevelop New File -> MonoTouch -> iPhone View).
When selecting a new iPhone View it creates an xib file, but no .h file is created, so how can I create outlets?
I usually drag an outlet from my label/button etc. to the .h file, but since it doesn't exist for this view, I don't know how to create the outlets.
Can someone point me in the right direction, since all articles on google are for the old versions, where outlets where created differently.
When you double-click a .xib in MonoDevelop, MonoDevelop will generate header files for your [Register]'d C# classes that subclass ObjC types and export them to a temporary Xcode project, where you can use Xcode to drag&drop Outlets and Actions.
Adding a new iPhone View file (.xib) does not auto-create any backing C# classes for you, it just creates the .xib, therefore MonoDevelop does not autogenerate any header files for you when you double-click the .xib.
When Xcode launches, you can manually create some Objective-C headers for this .xib and drag&drop outlets or actions to it (or you can create C# classes in MonoDevelop before double-clicking the .xib). When you switch back to MonoDevelop, MonoDevelop will "import" the header files, translating them into the equivalent C#.
While in Xcode, you can also add .xib's there and MonoDevelop will import those as well.
The Xamarin documentation has a good tutorial on this. There is a section for Adding Outlets and Actions to the UI using Interface Builder in Xcode4
Adding an Outlet In order to create the Outlet, use the following
procedure:
Determine for which control you want an Outlet.
Hold down the Control key on the keyboard, and then drag from the control to an empty space in your code file after the #interface
definition.

Using XCode storyboard to instantiate view controller that uses XIB for its design

I have a UIViewController subclass that I created previously that had its controls laid out in a XIB file.
I'd like to use this view controller in a storyboard now, but it seems although I can indicate a view controller's classname in the storyboard, I can't tell it to load the XIB.
I'd rather not move everything from the XIB to the storyboard but keep it in its separate XIB.
How can I get this UIViewController in the storyboard to load my XIB?
Delete the View contained by the view controller in the storyboard.
Then provide the view by configuring a nib file with the same name
as the view controller class. For example if the view controller
class is called MyViewController, name your xib file
MyViewController.xib.
EDIT Note that Swift seed 5 started breaking this technique, because it mangles the name of the .xib file it's looking for. See my answer here for workarounds: https://stackoverflow.com/a/25539016/341994 Basically this name matching was broken in iOS 8, but then Apple repented and fixed it so that it works again in iOS 9.

Create instance of class in nib file

Im going through Apple's OSX Cocoa (Your First Mac Application) tutorial and am up to refactoring the app delegate. I have created my own controller class.
I don't understand how to "Create an instance of the controller class in the nib file". I'm using Xcode 4.
Drag an 'Object' from the 'Object Library' in the right pane onto your nib. Next, select the object that you dragged into the nib, and then select the identity inspector (third icon from the left in the top right pane). From these, you can set a custom class. Set the class to be the custom controller that you have created. This will be created for you when the nib is initialized. You can then connect this to an IBOutlet in your AppDelegate (for that custom class).
I think what you want is on the inspector, click the third tab, and for the "Custom Class", select your view controller.

How to add Custom View class in XCode 4 iOS Project?

I create a subclass of UIView named "WebViewContainer", In Interface Builder 3 ,we can drag the WebViewContainer to MainViewController, but in xcode 4, I couldn't find that, in the "Custom Objects", it's empty:(
Drag a view object in to the window and change its default class to "WebViewContainer".
See this video on youtube http://www.youtube.com/watch?v=-u-Kdp-lYgM

Resources