调用pushViewController时EXC_BAD_ACCESS

发布于 2024-08-23 17:12:44 字数 559 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你是年少的欢喜 2024-08-30 17:12:44

当您尝试访问已释放的对象时,会引发 EXC_BAD_ACCESS ,并且在操作表关闭后,在主线程上调用 actionSheet:clickedButtonAtIndex: ,所以我猜测myViewController 指向的内容被释放。

它不一定是nil,事实上,这就是问题所在。指向的对象被释放,但指针不是nil

EXC_BAD_ACCESS is thrown when you try to access a released object, and actionSheet:clickedButtonAtIndex: is called on the main thread, after the action sheet is dismissed, so I'm guessing what's pointed by myViewController is released.

It doesn't have to be nil, in fact, that's the problem. The object pointed is released, but the pointer is not nil.

他夏了夏天 2024-08-30 17:12:44

我只是遇到了同样的问题,我的问题是我在分配成员变量时没有将其与 self 关联起来。

这导致了一个问题:(myTestViewController 是类成员)

TestViewController* test = [[TestViewController alloc] init];
    myTestViewController = testViewController;
    [testViewController release];
        [[self navigationController] pushViewController:myTestViewController animated:YES];

但是当我更改并用 self 协助类成员时,它起作用了。

TestViewController* test = [[TestViewController alloc] init];
    self.myTestViewController = testViewController;
    [testViewController release];
        [[self navigationController] pushViewController:myTestViewController animated:YES];

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)

TestViewController* test = [[TestViewController alloc] init];
    myTestViewController = testViewController;
    [testViewController release];
        [[self navigationController] pushViewController:myTestViewController animated:YES];

But when I change and assied the class member with self it worked.

TestViewController* test = [[TestViewController alloc] init];
    self.myTestViewController = testViewController;
    [testViewController release];
        [[self navigationController] pushViewController:myTestViewController animated:YES];
梦年海沫深 2024-08-30 17:12:44

我有类似的问题。我解决这个问题的方法是从我推送的视图控制器中删除 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.

握住你手 2024-08-30 17:12:44

tnx。

UIActionSheet 是从一个名为 MainRootViewController 的类中调用的。

myViewController 是该类 (MainRootViewController) 的成员。

完整代码是:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

myViewController = [[myViewController alloc] init];

[[self navigationController] pushViewController:myViewController animated:YES];

 }

tnx.

The UIActionSheet is called from within a class called: MainRootViewController

myViewController is a member in this class (MainRootViewController).

The full code is:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

myViewController = [[myViewController alloc] init];

[[self navigationController] pushViewController:myViewController animated:YES];

 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文