TabBarController, NSNotificationCenter, the hate!

Discussion in 'iOS Programming' started by mraheel, Jul 12, 2009.

  1. mraheel macrumors regular

    Joined:
    Apr 18, 2009
    #1
    Hi guys,
    So, i thought i had sorted this out, but I ran into a problem here..

    The situation:
    ViewControllerA sends a notification object after DidSelectrow in tableView.
    NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter];
    [nCenter postNotification name:mad:"go" object:book];

    Another ViewControllerB with different NIB file.
    in iniWithNIBFile {}
    NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter];
    [nCenter addObserver:self selector:mad:selector(Go name:mad:"go" object:nil];

    -(void)Goid)Notification{
    ShowAlert;
    }


    this worked properly in the normal setting. That is an app with no tabBarController/tabbar.

    However,
    When I made another new Tab Bar Application, I found, that None of the iniWithNIB methods worked. As if that step is totally skipped and not called at all.. iniWithNIBfile was the main method where i declared the NSNotificationCenter and addObserver etc..


    In All tabs, I found, none of the iniWithNIB's are called.

    I initially thought that Tabs with separate Nib's will be initialised when that specific tabbarItem is touched. And those tabs that have views sitting on the mainview.nib will be initialised default on application launch.
    On top of that, I iniWithNibName in the view controllers' of those separate xib files are not called at all. So I cant confirm this.


    I tried declaring (addObserver: method) in ViewDIDLoad. The message went across alright, but the program got stuck! when i tapped that specific Notification receiving tab in this case, residing in the same mainView.nib


    What I want to achieve is this.
    I required 2 view controllers to initialise on app launch. THe notification sender and receiver.
    To achieve this I put both viewControllers and their views in the same file - mainview.nib. But then, IniWithNIBfile doesnt get called for some reason. in TabController apps.
    BUT i need that method to declare the NSNotificationCenter addobserver method. This doesnt seem to work any where else.


    Is there anyway i can do this right without disturbing the InterfaceBuilder much?
    Any suggestions? alternatives?

    thanks
    (man, i've been bugging this place alot)
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    initWithCoder is called when an object is created from a nib. Add that to your viewController. You could also use awakeFromNib.
     

Share This Page