调用pushViewController时EXC_BAD_ACCESS
我在 UITabBarController
中有一个 UITableView
。
当我打电话时
[[self navigationController] pushViewController:myViewController animated:YES];
没有问题。
但是,当我从 UIActionSheetDelegate
内部调用同一行时,例如:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
我得到 EXC_BAD_ACCESS
。
似乎从不同的线程调用此行会导致此问题。
如何防止此 EXC_BAD_ACCESS
问题?
(注意 myViewController 不为零,或类似的东西)
谢谢!
I have a UITableView
inside a UITabBarController
.
When I'm calling
[[self navigationController] pushViewController:myViewController animated:YES];
there is no problem.
But, when I'm calling the same line from inside a UIActionSheetDelegate
, for example:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
I get EXC_BAD_ACCESS
.
It seems that calling this line from a different thread causing this issue.
How can I prevent this EXC_BAD_ACCESS
issue?
(notice that myViewController is NOT nil, or something like that)
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您尝试访问已释放的对象时,会引发
EXC_BAD_ACCESS
,并且在操作表关闭后,在主线程上调用actionSheet:clickedButtonAtIndex:
,所以我猜测myViewController
指向的内容被释放。它不一定是
nil
,事实上,这就是问题所在。指向的对象被释放,但指针不是nil
。EXC_BAD_ACCESS
is thrown when you try to access a released object, andactionSheet:clickedButtonAtIndex:
is called on the main thread, after the action sheet is dismissed, so I'm guessing what's pointed bymyViewController
is released.It doesn't have to be
nil
, in fact, that's the problem. The object pointed is released, but the pointer is notnil
.我只是遇到了同样的问题,我的问题是我在分配成员变量时没有将其与 self 关联起来。
这导致了一个问题:(myTestViewController 是类成员)
但是当我更改并用 self 协助类成员时,它起作用了。
I just had the same problem and mine was that I did not assine the member varible with self when I alloced it.
This causeed a problem: (myTestViewController is the class member)
But when I change and assied the class member with self it worked.
我有类似的问题。我解决这个问题的方法是从我推送的视图控制器中删除
self.navigationController.delegate = self;
。I had a similar problem. The way I fixed it was by removing
self.navigationController.delegate = self;
from my pushed view controller.tnx。
UIActionSheet 是从一个名为 MainRootViewController 的类中调用的。
myViewController 是该类 (MainRootViewController) 的成员。
完整代码是:
tnx.
The UIActionSheet is called from within a class called: MainRootViewController
myViewController is a member in this class (MainRootViewController).
The full code is: