Access Views Created in Interface Builder

I created a ChildViewController class and then a nib that uses this class.

Then I created a BaseView that includes some buttons and some text that I will change programmatically.

Then I created two more views ("Boy and Girl"), which I want to stack for the basic view, so that the background color differs from some graphic elements in ImageView. I named the looks that I created in IB 'Boy' and 'Girl' ...

But when I return to my code where I call ChildViewController, I am not sure how to access the created views so that I can call insertSubView. Do I need to create them in code? (perhaps in ViewDidLoad?) Does nib create instances on boot?

I am confused about how to handle multiple views for a single ViewController

change ===================

@Pablo Santa Cruz

Your answer assumes that I have two tips and two view controllers (one for each view). I want to know if I can use one tip and one controller and load in UIViews. It seems silly to create another tip and controller when everyone wants to do is change the background color and some graphics. Can't I programmatically load UIViews into a UIViewController?

+3
source share
3 answers

IBOutlets App Controller Xcode, IB (ctrl-click ) .

.

Xcode :

@interface AppController : NSObject
{
   IBOutlet Girl girlIvarName1;
   IBOutlet Boy boyIvarName2;
}


@end
+2

UIView , , IB ( 1)

, , , . 100,

, , , UIViewController, initWithNibName NIB,

UIView *aView = [self.view viewWithTag:100];
+2

You can get instances for your IBuilder views with this code snippet:

boyViewController = [[BoyViewController alloc] initWithNibName:@"BoyViewController" bundle:nil];
girlViewController = [[GirlViewController alloc] initWithNibName:@"GirlViewController" bundle:nil];

Assuming your NIB file names are BoyViewController and GirlViewController. In these cases, you can do whatever you need. IE by adding them to the parent view (with the message addSubView on the parent).

0
source

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


All Articles