我正在做一个项目,我正在尝试以编程方式尽我所能。
我必须将 UIBarButtonItem 添加到在 App Delegate 中创建的 NavigationController 的导航栏。
WPViewController *mainVC = [[WPViewController alloc] initWithNibName:@"WPViewController_iPhone" bundle:nil];
UINavigationController *navCon = [[UINavigationController alloc] init];
[navCon pushViewController:mainVC animated:NO];
[self.window addSubview:navCon.view];
然后在此处声明的 WPViewController
的实现文件中,我创建并添加了 barbuttonitem 作为 VC 的导航项:
UIBarButtonItem *rBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(test)];
self.navigationItem.rightBarButtonItem = rBarButtonItem;
在此之前声明了一个名为 test 的方法,它只记录“test”,但是当我单击该按钮时,应用程序崩溃了。
请帮帮我,这个错误快把我逼疯了。
注意事项:
- 我在我的项目中使用 ARC
- 以前从未遇到过类似的错误
最佳答案
ARC 中的“发送到释放实例的消息”意味着编译器在您的消息可以发送之前已经标记并释放了您的项目。
在调试器中设置 NSZombieEnabled、MallocStackLogging 和 guard malloc。然后,当您的应用程序崩溃时,在控制台中输入:
(gdb) info malloc-history//崩溃对象的地址即0x543216//
关于ios - UIBarButtonItem 让我的 iPhone 应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8248663/