iPhone 加速计导致应用程序崩溃

发布于 2024-07-25 12:12:56 字数 314 浏览 5 评论 0原文

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

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

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

我缺少什么?

谢谢

I have an navigation-based app that I want to use the accelerometer to detect a shake and cause a scroll view to scroll to the next page. I have added accelerometer code to the view controller of my scrollView, and it works great; a shake calls my page change method. But when I unload the scrollViewController from the navigation stack the app crashes.

I set up the accelerometer in the viewDidLoad method of the scrollViewController, and respond to a shake in the accelerometer: didAccelerate: delegate method.

When the scrollViewController gets deallocated, the app crashes.

What am I missing?

Thanks

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

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

发布评论

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

评论(4

余生一个溪 2024-08-01 12:12:56

在另一个线程中找到了答案:

你怎么样在iPhone上释放共享加速器实例?

当我的scrollView释放时,我需要将加速计的委托设置为nil。 加速度计是一个单例,它保留对其委托的引用,在本例中是我的scrollViewController。 当我的scrollViewController从堆栈中弹出时,引用悬​​空,导致应用程序崩溃。

感谢菲尔·纳什的回答!

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!

梦初启 2024-08-01 12:12:56

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

What is your update rate on the accelerometer? I've heard of weird things happening if it's too high.

何以畏孤独 2024-08-01 12:12:56

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

I can't make a comment so I had to post this in the answer. can you display how you new view page load. as I am understanding is once the you shake it it suppose to switch to a new view. Can you display your call to the new view.

枕花眠 2024-08-01 12:12:56

简单:通过设置委托方法,您已经告诉另一个对象(加速计)滚动视图存在。

但是当它不再存在时你是否告诉它,所以它不能不向它发送任何消息?

我猜不会。 您需要再次设置委托,这次设置为零。

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.

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