Generic XIB in multiple View controllers on iPhone

I have an iPhone app with multiple view controllers. I do not want to use the same method and create a general view in all controllers. So my questions are: how to use this general representation in all controllers.

+1
source share
3 answers

Use initWithNibNamed: "your xib name" when you assign your new view controller. It's simple.

+2
source

Same thing, but we can avoid the definition of a variable -

[self.view addSubview:[[(NavAppAppDelegate *)[[UIApplication sharedApplication] delegate] headerview] view]]; 
+1
source

ok, so you need to create it in the Application Delegate once. in .h

 @property(nonatomic,strong) uiviewcontroller headerview; 

in .m

 @synthesize headerview=_headerview; 

then highlight it in "doneFinishLaunchingWithOptions" in appdelegate as singleton

 self.headerview = [[headerview alloc] initWithNibName:@"headerview" bundle:nil]; 

So, every time you want to add it to your view. Create an object from the application delegate in your class after importing it.

 applicationdelegate app = [uiapplication sharedapplication]delegate]; [self.view addsubview:app.headerview.view]; 
0
source

All Articles