开发者

EXC_BAD_ACCESS although objects are not freed?

I have the following problem in my code:

    UITableViewController *controller = nil;


switch (indexPath.row) {
    case 0:
        controller = self.kundenTableViewController;
       开发者_JAVA百科 break;
    case 1:
        controller = self.projekteTableViewController;
        break;
    case 2:
        controller = self.leistungenTableViewController;
        break;
    case 3:
        controller = self.zeitenTableViewController;
        break;
}

[self.navigationController pushViewController:controller animated:YES];

All those four view controllers are properly defined in the .h-file and are synthesized manually (and yes, all are exactly the same, I double checked):

- (LeistungenTableViewController*)leistungenTableViewController {
if (leistungenTableViewController == nil) {
    // Neu erzeugen
    leistungenTableViewController = [[LeistungenTableViewController alloc] initWithNibName:@"LeistungenListeView" bundle:nil];
} 
return leistungenTableViewController;

}

Now, something strange happens: if the case 0: is called, controller becomes self.kundenTableViewController. Then I get an EXC_BAD_ACCESS at the last line, where the view controller is pushed onto the stack. This does only happen with this particular controller, not with the other ones. I tried NSZombies and checked via NSLog whether the controller gets initialized properly, but everything seems fine. Any ideas?

Update: here's the code for the four controllers:

- (KundenTableViewController*)kundenTableViewController {
if (kundenTableViewController == nil) {
    // Neu erzeugen
    kundenTableViewController = [[KundenTableViewController alloc] initWithNibName:@"KundenListeView" bundle:nil];
} 
return kundenTableViewController;

}

- (LeistungenTableViewController*)leistungenTableViewController {
if (leistungenTableViewController == nil) {
    // Neu erzeugen
    leistungenTableViewController = [[LeistungenTableViewController alloc] initWithNibName:@"LeistungenListeView" bundle:nil];
} 
return leistungenTableViewController;

}

- (ProjekteTableViewController*)projekteTableViewController {
if (projekteTableViewController == nil) {
    // Neu erzeugen
    projekteTableViewController = [[ProjekteTableViewController alloc] initWithNibName:@"ProjekteListeView" bundle:nil];
} 
return projekteTableViewController;

}

- (ZeitenTableViewController*)zeitenTableViewController {
if (zeitenTableViewController == nil) {
    // Neu erzeugen
    zeitenTableViewController = [[ZeitenTableViewController alloc] initWithNibName:@"ZeitenListeView" bundle:nil];
} 
return zeitenTableViewController;

}

I just can't figure out why it only happens with the first one.


Sounds like something goes wrong with intialization of the nib file, in particular once the -loadView method which is called (which happens just before the view controller is displayed and is responsible for hooking up the IBOutlets with the proxy objects). Are you sure every IBOutlet is properly connected and the view is connected as well? You might want to check your nibs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜