当用户按下注销按钮时,如何停止更新位置
我正在使用mapview在Swift中开发应用程序,并使用nsstimer每3分钟获取当前位置。我可以获取位置,一切正常。在我的MapView控制器当用户按下注销按钮时,如何停止更新位置
示例代码:鉴于didload方法
let timer = NSTimer.scheduledTimerWithTimeInterval(180.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: true)
func timeToMoveOn()
{
print(latitude)
print(longitude)
}
这有助于为每3分钟
示例代码其写在另一个视图控制器注销操作获取当前位置:
var viewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
var appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as?
AppDelegate)!
appDelegate.window?.rootViewController = viewcontroller
appDelegate.window!.makeKeyAndVisible()
它也可以正常工作,并且能够返回到登录页面,但问题是当我点击注销操作func timeToMoveOn
正在更新当前位置我不想在用户点击注销操作时更新位置。如何停止NSTimer?
我已经搜索了其他堆栈溢出的答案,并不支持我,因为我的nstimer和注销操作在不同的控制器中执行。有人可以帮我解决这个问题吗?
Logout_Button Clicked_Event点击时调用其他的MapView控制器的NSTimer方法:
var MapVC:mapviewcontrolle = mapviewcontrolle() // diffrent view controller object
MapVC.timer.invalidate()
注销按钮点击事件呼叫,.. –
计时器显示我错误....因为我使用不同的控制器,我不能打电话定时器...怎么办? – antonyraja
创建控制器对象....并访问该定时器对象...调用该方法 –
定时器.invalidate()调用退出时间 –
在那里我必须包括该代码...以及如何调用注销时间?你简单地解释...谢谢你的快速回应@jayesh miruliya – antonyraja