开发者

EXC_BAD_ACCESS on trivial code

This is the code:

UITabBarController *tbc = [[UITabBarController alloc]init];
tbc.viewControllers = [NSArray arrayWithObjects:ptlc,cvc,gvc,nil];
[self.navigationController pushViewController:tbc animated:YES];
[tbc release];

This is the last part of the code in tableView:didSelectRowAtIndexPath:. When selecting the row the UITabarController shows fine, but when hitting the "back" button on the UINavigationController, the program cr开发者_StackOverflow社区ashes after a second without printing any description on the console. The debugger just points me "Thread 1: Program received signal: "EXC_BAD_ACCESS"." on this line:

 int retVal = UIApplicationMain(argc, argv, nil, nil);

On "main.m". Incredibly, removing the last line solves the problem. ptlc cvc and gvc are controllers which I first alloc inited and that I release after the last line of this code sample.


Solved it myself using the profile tool "zombies". It showed me that an UIImage was receiving a release message after being deallocated. It was because I was using the same UIImage for two different UITabBarItems on the UITabBar.


since theres nothing visibly wrong with that code, memory wise; it leads me to believe it's occurring because you shouldn't use a UITabBarController as a viewcontroller in a UINavigationController stack. From the Apple Documentation on UITabBarController:

Before creating a tab bar interface, you need to decide how you intend to use it. Because it imposes an overarching organization on your data, there are only a handful of appropriate ways to use a tab bar interface:

  • Install it directly in your application’s main window.
  • Install it as one of the two root views in a split view interface. (iPad only)
  • Present it modally to display some data that requires its own mode-based organization.
  • Display it from a popover. (iPad only)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜