0

I use Objective-C to develop an iOS tabBar app. When users open the app, it is in tab1. When users click a picture in tab1, the app will jump to tab3 with the picture's name.

The problem is where to call addObserver in tab3 since tab3 never opens?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Miken
  • 35
  • 8
  • 1
    It is unclear what method you mean by `addObserver` (there are at least two distinct groups of methods with that name) or why you want to do so. In general, if a view controller needs observe something when it is not on screen, you're probably violating MVC. https://developer.apple.com/library/mac/documentation/General/Conceptual/CocoaEncyclopedia/Model-View-Controller/Model-View-Controller.html If you just need to observe when you're onscreen, use `viewDidAppear` and `viewWillDisappear`. – Rob Napier Jul 07 '16 at 00:13

1 Answers1

0

If I get your question correctly you just want to open tab3 when you click a photo from tab 1

IMO, it should have something like window->mainController->tabController [tabs]

In your tab1Controller you can setup a delegate lets call it "Tab1ControllerDelegate" having a method named "tab1DidSelectSomething:(NSString *)something". then in your mainController you can assign the delegate to self.

 i.e.
  tab1Controller.delegate = self;

In your tab1Controller picker action you can do something like:

if(_delegate){ [_delegate tab1DidSelectSomething:<whatEverheSelected>]; }

Then in your mainController:

-(void)tab1DidSelectSomething:(NSString *)something{ // get the viewController here UIViewController *controller = _tabController.viewControllers[2]; [controller updateselected:something]; _tabController.selectedIndex = 2; }

Joshua
  • 2,432
  • 1
  • 20
  • 29