UIAccelerometer EXC_BAD_ACCESS 设备崩溃

发布于 2024-09-30 11:44:07 字数 953 浏览 2 评论 0原文

我在实现 UIAccelerometer 时遇到了一些奇怪的问题。 我有一个 UITableViewController,我不想使用 UIAccelerometer,但是在按下我想在 UIViewController 内激活的行后,当我使用模拟器时一切都很好,但是当我使用设备 iPhone 3G 来测试它时,我得到了 EXC_BAD_ACCESS按返回按钮。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


     ShakeControl *percView = [[ShakeControl alloc] init];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:percView animated:YES];
     [percView release];


}

当我禁用 [percView release]; 时它工作正常,但听起来不像解决方案。 任何想法将不胜感激。

抖动控制实现:

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0 / kUpdateFrequency];
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];

}

- (void)viewDidUnload {
    [super viewDidUnload];

    [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
}

Thx

I am facing a bit strange problem with implementation of UIAccelerometer.
I have a UITableViewController where I don't wanna use UIAccelerometer, but after pressing on of the rows I wanna activated one inside a UIViewController, everything is fine when I use simulator, but when I use device iPhone 3G to test it, I got EXC_BAD_ACCESS by pressing return button.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


     ShakeControl *percView = [[ShakeControl alloc] init];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:percView animated:YES];
     [percView release];


}

It works fine when I disable [percView release];, but it does not sounds like solution for.
Any Idea would be appreciated.

Shake control implementation:

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0 / kUpdateFrequency];
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];

}

- (void)viewDidUnload {
    [super viewDidUnload];

    [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
}

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

笑脸一如从前 2024-10-07 11:44:07

viewDidUnload 方法仅在特定情况下才会被调用,例如内存警告。您还必须删除 dealloc 中的委托。

The viewDidUnload method will get called only in specific case, such as memory warning. You have to remove the delegate in dealloc too.

爱本泡沫多脆弱 2024-10-07 11:44:07

尝试在关闭后释放它,我不确定pushViewController是否保留。

Try releasing it after you dismiss it, I'm not sure if pushViewController retains.

柳絮泡泡 2024-10-07 11:44:07

您可以设置环境变量 NSZombiesEnabled & NSAutoreleaseFreedObjectCheckEnabled 值为 1。
这将阻止对象真正被释放,然后您应该获得控制台日志,指示过度释放的来源。

您可以使用“使用性能工具运行”->一旦您知道哪个对象被过度释放,并查看调用保留/释放的每个位置以发现不平衡,即可进行分配。

You could setting the environment variables NSZombiesEnabled & NSAutoreleaseFreedObjectCheckEnabled with a value of 1.
This will prevent objects from really being deallocated, then you should get console logs indicating where the over-release is coming from.

You could use Run With Performance Tools -> Allocations once you know which object is being over-released and see every location where a retain/release was called to spot the imbalance.

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