1

我有一个基于导航的应用程序,我想使用加速度计检测抖动并导致滚动视图滚动到下一页。我已将加速度计代码添加到我的 scrollView 的视图控制器中,效果很好;震动调用我的页面更改方法。但是当我从导航堆栈中卸载 scrollViewController 时,应用程序崩溃了。

我在scrollViewController的viewDidLoad方法中设置了加速度计,并在加速度计中响应抖动:didAccelerate:委托方法。

当 scrollViewController 被释放时,应用程序崩溃。

我错过了什么?

谢谢

4

4 回答 4

3

Found the answer in another thread:

How do you release a shared accelerator instance on the iPhone?

I needed to set the accelerometer's delegate to nil when my scrollView deallocated. The accelerometer is a singleton that retains a reference to it's delegate, in this case my scrollViewController. When my scrollViewController popped off the stack, the reference was left hanging, crashing he app.

Thanks to Phil Nash for the answer!

于 2009-06-18T20:22:53.487 回答
0

Simple: by setting the delegate method you have told another object (the accelerometer) that the scrollview exists.

But did you tell it when it ceased to exist, so it could no not to send any messages to it?

I guess not. You need to set the delegate again, to nil this time.

于 2009-06-18T20:23:33.487 回答
0

加速度计的更新速率是多少?我听说如果它太高会发生奇怪的事情。

于 2009-06-18T19:04:00.303 回答
0

我无法发表评论,所以我不得不在答案中发布这个。您可以显示新视图页面的加载方式吗?据我了解,一旦您摇动它,它就会切换到新视图。你能显示你对新视图的调用吗?

于 2009-06-18T20:09:49.160 回答