停止从 iPhone 用户界面更新位置?
是否可以从 iPhone 的 UI 启动/停止位置更新?我需要应用程序显示我的位置,除非我单击“停止”然后再次“开始”。
我似乎无法做到这一点...我的位置已正确显示,我还创建了两个 IBButton 并为每个按钮创建了一个函数,但是,当我单击每个按钮时,我的应用程序崩溃了。我将这些函数放在 viewcontroller.m 下。
我对此有点陌生,所以任何帮助将不胜感激。谢谢!
(IBAction)开始更新:(CLLocation *)位置 {
[位置开始更新位置];
}
(IBAction)停止更新:(CLLocation *)位置 {
[位置停止更新位置];
}
Is it possible to start / stop location updates from the UI of the iphone? All I need from the app is to show me my location unless I click "stop" and then "start" again.
I can't seem to be able to do that...I have my location displayed properly, and I also created two IBButtons and created a function for each of them, however, my app crashes when I click on each one of those buttons. I placed those functions under the viewcontroller.m.
I am kind of new to this, so any help would be appreciated. Thanks!
(IBAction)startUpdating: (CLLocation *)location
{[location startUpdatingLocation];
}
(IBAction)stopUpdating: (CLLocation *)location
{[location stopUpdatingLocation];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
start/stopUpdatingLocation 是 CLLocationManager 实例方法,而不是 CLLocation 实例方法...因此创建一个 CLLocationManager 实例。
.h
.m 在视图加载/或初始化周期中的某个位置:
上面的操作也永远不会起作用,因为操作中冒号后面的东西将是发送操作的对象,在您的情况下是 UIButton 。
start/stopUpdatingLocation are
CLLocationManager
instance methods, rather thanCLLocation
instance methods... so create aCLLocationManager
instance..h
.m somewhere in the view load/ or init cycle:
also your action above will never work, because the thing after a colon in an action will be the object that sent the action, a UIButton in your case.