大佬教程收集整理的这篇文章主要介绍了ios – Swift performSegueWithIdentifier不工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@IBACtion func loginTapped(sender: AnyObject) { let username = usernameField.text let password = passwordField.text if username.isEmpty || password.isEmpty { var emptyFieldsError:UIAlertView = UIAlertView(title: "Please try again",message: "Please fill in all the fields we can get you logged in to your account.",delegate: self,cancelButtontitle: "Try again") emptyFieldsError.show() } PFUser.logInWithUsernameInBACkground(username,password:password) { (user: PFUser?,error: NSError?) -> Void in if user != nil { self.performSegueWithIdentifier("Klikur",sender: self) } else { if let errorString = error!.userInfo?["error"] as? String { self.errormessage = errorString } self.alertView("Please try again",message: "The username password combiation you have given us does not match our records,please try again.",buttonName: "Try again") } } }
我将故事板ID设置为“测试”,并且当输入正确的信息时它不是切换视图控制器。有人可以帮我解决我的问题吗?
至少有一个问题是:
self.performSegueWithIdentifier("Test",sender: self)
应该:
dispatch_async(dispatch_get_main_queue()) { [uNowned self] in self.performSegueWithIdentifier("Test",sender: self) }
记住,所有UI操作必须在主线程的队列上执行。你可以通过检查来证明自己是错误的线程:
NSThread.ismainThread() // is going to be false in the PF completion handler
附录
如果没有任何机会,自己可能会变得没有,例如由于不需要而被解雇或以其他方式解除配置,那么您应该以弱的身份捕获自我,而不是无人知晓,并且使用安全的解开方式:如果让s = self {s.dostuff() }或可选链接:self?.dostuff(…)
附录2
这似乎是一个受欢迎的答案,所以在这里提到这个更新的选择很重要:
NSOperationQueue.mainQueue().addoperationWithBlock { [weak self] in self?.performSegueWithIdentifier("Test",sender: self) }
注意,从https://www.raywenderlich.com/76341/use-nsoperation-nsoperationqueue-swift:
附录3
苹果在这里隐藏单线规则:
参考:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKit_Framework/
以上是大佬教程为你收集整理的ios – Swift performSegueWithIdentifier不工作全部内容,希望文章能够帮你解决ios – Swift performSegueWithIdentifier不工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。