我正在做一个项目,我正在尝试以编程方式做最多的事情。
我必须将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中的“发送到已释放实例的消息”表示编译器已在发送消息之前标记并释放了您的项目。
在调试器中设置NSZombieEnabled,MallocStackLogging并保护malloc。然后,当您的应用崩溃时,在控制台中输入以下内容:
(gdb)info malloc-history //崩溃对象的地址,即0x543216 //
关于ios - UIBarButtonItem使我的iPhone应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8248663/