Xcode - How to connect XIB to the ViewController class

First I created my TestViewController.h and * .m. After that, my TestView.xib.

Now I need to say my xib: "Yes, please take the TestViewController class as my file owner."

I open my xib, go to the Identity Inspector of my file device and select "Custom Class" in TestViewController.

But this seems insufficient - because when I open TestView.xib and then select "View Editor Assistent", it should call the corresponding ViewController on the right side of the split screen - in my case, "TestViewController .hour." But that is not so!

Does xib need to be connected in any way with its view manager by dragging and dropping lines into files, how do you do this with exits and actions?

+55
objective-c xcode viewcontroller
Jun 27 '12 at 11:57
source share
6 answers

Press to select xib. Now select the owner of the file. In the attribute panel on the right side, select the third tab, "Identity Inspector." There is a header named Custom Class . Give your controller controller name there. After that, you can associate the items with the file owner.

enter image description here

+82
Jun 27 2018-12-12T00:
source share

In the view controller, create a "view" (UIView) and mark it as an IBOutlet. (When you use the correct defaults / templates when creating files in xcode, this property should already be there.) In Interface Builder, create a link between the main view and the view / view of the file manager / owner view. Only for the full picture: when creating / distributing a view controller, you should run it with the corresponding XIB file. This is the moment when the view controller object is attached to the view that is created from the XIB file.

+17
Jun 27 '12 at 12:11
source share

I think I came across this situation when I created a subclass of UIViewController, but forgot to check β€œwith .xib for UI” when I did this. Later I came back and created .xib separately.

Here's another step by step to link your new UIViewController and .xib.

  • Select File Owner in the Placeholders section in the IB left pane. In the Property Inspector (right panel IB), select the third tab and edit the "Class" in the "Custom Class" section as the name of your new subclass of UIViewController.

  • Then press Ctrl or right-click on File Owner in the left pane and draw a line at the top level of the View in the Objects section of the left pane. Select the "view" output and everything will be ready.

Now you can configure other points and actions. You are ready to instantiate your view controller in code and use initWithNibName and your nib name to load it.

+17
Aug 01 '13 at 20:30
source share

1) First, like each of them, give the name of the view controller in the File Owner class

2) Select "File Owner", drag a line from there to view this connection.

3) Create an instance of the View controller and add it to the window so that the code snippet is as follows,

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil]; 

4) Finally, add the view controller view as a subview to window.TO do this so that the encoding is as follows,

 [window addSubview:[controller view]]; 

Try the following snippet on appdelegate

 - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil]; [window addSubview:[controller view]]; } 

5) Use the following snippet to increase the window size so that no delays are displayed

 [controller.view setFrame:[[UIScreen mainScreen] applicationFrame]]; 

Now you will see the controller of your kind, as you expected ...

Hope this helps ...

+6
Apr 05 '13 at 4:51
source share

yes, you must add the view property to the file owners of this view controller from the interface constructor:

0
Jun 27 2018-12-12T00:
source share

select the fileownr file, go to the identity inspector window and change the class name of the file owner to your .h file that will be connected.

0
Jun 27 2018-12-12T00:
source share



All Articles