I have an iPhone Application with multiple view controllers , in all view controller's header is common. I dont want to use the same method and create common view in all controllers. So My questions is how do i use this common view in all controllers.
Asked
Active
Viewed 2,203 times
3 Answers
2
Use initWithNibNamed:"name of your xib" when you alloc your new view controller. It's simple.

John Smith
- 2,012
- 1
- 21
- 33
-
Hi Teodor thanks for replying but my problem is like header view is same in all class and i dont want to create in xib again and again i have created once and i use that part only in all view controller class – iSanjay Jul 18 '12 at 10:12
-
So you have 1 header for the one xib, and you wanna share them with all controllers, right? – John Smith Jul 18 '12 at 10:20
-
Open your xib, and in the Utilities menu click the Identity inspector. There, in the "Custom class" section (on the top) select your header file. – John Smith Jul 18 '12 at 10:23
-
The answer is above. After doing that, all outlets declared in that header, will be seen in your xib. Do not hesitate to accept the answer if it was good enough. Cheers! – John Smith Jul 18 '12 at 10:24
-
Does this work if each controller has its own xib file? If so how do you add the header xib as well as the controller xib? – jhabbott Mar 26 '13 at 02:42
1
Same but we can avoid defining a variable -
[self.view addSubview:[[(NavAppAppDelegate *)[[UIApplication sharedApplication] delegate] headerview] view]];

John Conde
- 217,595
- 99
- 455
- 496

Rijesh
- 31
- 1
- 3
0
ok so you have to create it in Application Delegate once. in .h
@property(nonatomic,strong) uiviewcontroller headerview;
in .m
@synthesize headerview=_headerview;
then alloc it in "didFinishLaunchingWithOptions" in appdelegate as singleton
self.headerview = [[headerview alloc] initWithNibName:@"headerview" bundle:nil];
So every time you want to add it to your view. Create object from application delegate in your class after import it.
applicationdelegate app = [uiapplication sharedapplication]delegate];
[self.view addsubview:app.headerview.view];

Mina Nabil
- 676
- 6
- 19
-
Hi Mina Thanks for putting your answer this also works. but sorry before your answer i already accepted other one.Both are working for me thanks.cheers! – iSanjay Jul 18 '12 at 11:42