UIAccelerometer EXC_BAD_ACCESS 设备崩溃
我在实现 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
viewDidUnload
方法仅在特定情况下才会被调用,例如内存警告。您还必须删除dealloc
中的委托。The
viewDidUnload
method will get called only in specific case, such as memory warning. You have to remove the delegate indealloc
too.尝试在关闭后释放它,我不确定pushViewController是否保留。
Try releasing it after you dismiss it, I'm not sure if pushViewController retains.
您可以设置环境变量 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.