[英]How to stop updating location when user presses logout button in swift
I am developing a application in Swift using mapview and am fetching current location for every 3 minutes using nsstimer. 我正在使用mapview在Swift中开发一个应用程序,并使用nsstimer每3分钟获取一次当前位置。 I can able to fetch location and everything works fine.
我可以获取位置,并且一切正常。
Sample code in my mapview controller:In view didload method 我的mapview控制器中的示例代码:在视图didload方法中
let timer = NSTimer.scheduledTimerWithTimeInterval(180.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: true)
func timeToMoveOn()
{
print(latitude)
print(longitude)
}
It helps to fetch current location for every 3 minutes 每3分钟可获取一次当前位置
Sample code for logout action which written in another view controller: 在另一个视图控制器中编写的注销操作的示例代码:
var viewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
var appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as?
AppDelegate)!
appDelegate.window?.rootViewController = viewcontroller
appDelegate.window!.makeKeyAndVisible()
It also works fine and am able to return to login page, but the PROBLEM is when I tapped logout action that func timeToMoveOn
is keep on updating current location I don't want to update location when the user tapped logout action. 它也可以正常工作,并且能够返回登录页面,但是问题是当我点击注销操作时func
timeToMoveOn
一直在更新当前位置时,我不想在用户点击注销操作时更新位置。 How to stop NSTimer? 如何停止NSTimer?
I have searched other Stack Overflow answers and that does not support me because my nstimer and logout action are performing in different controllers. 我搜索了其他Stack Overflow答案,但不支持我,因为我的nstimer和注销操作在不同的控制器中执行。 Can someone help me out to solve this problem?
有人可以帮我解决这个问题吗?
Logout_Button Clicked_Event click time call that NSTimer method of other mapview controller : 其他mapview控制器的NSTimer方法的Logout_Button Clicked_Event点击时间调用:
var MapVC:mapviewcontrolle = mapviewcontrolle() // diffrent view controller object
MapVC.timer.invalidate()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.