0

I have 5 tabs in my iphone app, each tab have different viewcontrollers inside and I want to show & hide one common view (not viewcontroller) for all tabs and viewcontrollers.

I can make one common class for that, then how can i show the view from different classes by setting its frame .I have tried by presenting a common viewcontroller and a view inside it, but when i trying to show it, it shows a black screen, Please help me. Thanks.

Mumthezir VP
  • 6,251
  • 6
  • 28
  • 57
  • You can add your view to window in AppDelegate – Thilina Chamath Hewagama Jul 29 '15 at 10:15
  • @ThilinaCháminHewagama; if the view is not programmatically created? – Mumthezir VP Jul 29 '15 at 10:17
  • I'd create a base view controller with the option to opt that in (but the window can be an option to depending on the app architecture). The view itself should have it's own .xib file but then it's programmatically added (and not created). – Robert Gummesson Jul 29 '15 at 10:18
  • When you want to show common view ? On tab change or in particular method of respective view controller? Please show your code, how did you present common controller? – VRAwesome Jul 29 '15 at 10:22
  • @mvp, if the view is not programmatically created. how do you design the view ? , xib or storyboard ? – Thilina Chamath Hewagama Jul 29 '15 at 10:25
  • @ThilinaCháminHewagama; it is xib. – Mumthezir VP Jul 29 '15 at 10:49
  • Create a viewcontroller with a .xib file, design your view in the xib properly. ABCViewController.h ABCViewController.m ABCViewController.xib Then, in AppDelegate, create an instance from ABCViewController using initWithNibName, add the viewcontroller's view as a subview to the window. – Thilina Chamath Hewagama Jul 29 '15 at 11:02
  • @ThilinaCháminHewagama: yes, that s a point. but how how can call it from my viewcontroller. – Mumthezir VP Jul 29 '15 at 12:16
  • add a reference to your vc in AppDelegate, @property (nonatomic, strong) ABCViewController *abcViewController; - (void) showExtraView{ if (_abcViewController == nil){ _abcViewController = [[ABCViewController alloc] initWithNibName:@"ABCViewController" bundle:nil]; } [self.window addSubview:_abcViewController.view]; } -(void)hideExtraView{ [_abcViewController.view removeFromSuperview]; } call AppDelegate's method from your view controller witch is in the tab – Thilina Chamath Hewagama Jul 29 '15 at 12:39
  • @ThilinaCháminHewagama: Thank you so much! – Mumthezir VP Jul 30 '15 at 06:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84669/discussion-between-mvp-and-thilina-chamin-hewagama). – Mumthezir VP Jul 30 '15 at 10:22

0 Answers0