简体   繁体   中英

Pushing view to second Navigation Controller

I have have a tabbar application which has two items. Those two different tabbar items contains 2 different navigation controllers. First Navigation Controller works fine but when i want to push a view to second navigation it generates "Application tried to push a nil view controller on target".

here is the code for where i pushing a view to second navigation controller.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

TabNavAppDelegate *appDelegate = (TabNavAppDelegate *)[[UIApplication sharedApplication] delegate];
JJ_MapAnnotation *anno = (JJ_MapAnnotation *) [depotsArray objectAtIndex:indexPath.row];
if(self.secondViewController ==nil)
{
    SecondViewController *secView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.secondViewController == secView;
    [self.secondViewController.map addAnnotation:anno];
    [secView release];
}


secondViewController.title = [NSString stringWithFormat:@"%@", [anno title]];

[appDelegate.navController pushViewController:secondViewController animated:YES]; 

I bet that in the line:

if(self.secondViewController ==nil)

self.secondViewController is not nil nor is a valid object. Probably with some trash in there. When you do that kind of dynamic allocation, make sure your object becomes nil after releasing it. Otherwise you can have cases like this one. I hope it helps

UPDATE:

== operator is incorrect here ;)

self.secondViewController == secView; //WRONG
self.secondViewController = secView; //OK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM