Use Nav Cont from A VIew Controller from NSObject

Discussion in 'iPhone/iPad Programming' started by newtoiphonesdk, Mar 10, 2012.

  1. macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    Basically, in my FirstViewController, I have an IBAction to push a ViewController using the navigationController.
    Code:
    - (IBAction)openInbox:(UIButton*)sender {  
        NSLog(@"Trying to launch displayInboxTable");
        UIViewController *inboxVC=[[XLappMgr get ]getInboxViewController];
        [self.navigationController pushViewController:inboxVC animated:YES];
    }
    I also have a NSObject file for several of my methods, and want to perform the same action when one of those methods is called. Since an NSObject doesn't have a navigation controller, I set up the code like this:
    Code:
    NSLog(@"CodeCalled");
    UIViewController *inboxVC=[[XLappMgr get ]getInboxViewController];
                        FirstViewController *appDelegate = (FirstViewController *)[[UIApplication sharedApplication] delegate];
    
                        [appDelegate.navigationController pushViewController:inboxVC animated:YES];
    I try to run the code, and the NSLog gets called, but the app crashes with this in console for reason:
    Code:
    2012-03-10 22:06:47.450 Bell Avenue[341:707] CodeCalled
    2012-03-10 22:06:47.451 Bell Avenue[341:707] -[BellAvenueAppDelegate navigationController]: unrecognized selector sent to instance 0x2e6ba0
    2012-03-10 22:06:47.453 Bell Avenue[341:707] *** Terminating app due to uncaught exception 
    Why is it trying to pull a navigation controller from the AppDelegate for my code, instead of from FirstViewController?
     

Share This Page