PDA

View Full Version : Use Nav Cont from A VIew Controller from NSObject




newtoiphonesdk
Mar 10, 2012, 10:16 PM
Basically, in my FirstViewController, I have an IBAction to push a ViewController using the navigationController.
- (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:
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:
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?