How to save controllers from xib

As a newbie, IB and all possible connections are confusing to me. Most of the tutorials I found are what I would call the reincarnation of the spaghetti code, in which obfuscation is all the connections created by drag and drop. Of course, I want to use IB to layout the views (sizing and placing visual elements), which IB is great. But the controller is not a point of view, so it is less confusing if all my controllers are exclusively code and are not displayed anywhere in IB. I suspect this will minimize spaghetti. It also encourages a one-time warning. To this end, the question arises here, where can I find examples of projects that adhere to this strategy?

+3
source share
2 answers

I do not have a set of sample projects, but I will give you some information about how everything works, and when you should create a controller in a XIB file or in code.

If your controllers are created dynamically using a user action, you usually do not create them in a XIB file. Instead, you will create them in code, for example, mention of harm. Once you do this, you will still need a mechanism to connect this controller, which was created in the code, to the user interface elements that you created in IB.

The mechanism that IB provides to resolve this issue is File Owner. Mastering the file owner is essential for getting the Interface Builder.

, "XIB ", , XIB . , , XIB . NIB , NSBundle - [NSBundle loadNibNamed: ownwer: options:]. owner - XIB/NIB. , , , , , NSBundle. iPhone NIB . UIViewController . loadView UIViewController :

- (void)loadView {
    [[self nibBundle] loadNibNamed:[self nibName] owner:self options:nil];
}

, XIB , .

, - . , , . MainWindow.xib. , -.

+4
. , , , , IBOutlets IBActions XIB/NIB, , - , XIB/NIB "self" as , IB "File Owner", .
+1

Source: https://habr.com/ru/post/1709042/


All Articles