我正在使用xcode 7 beta和swift 2.0。我正在学习教程(youtube.com/watch?v=PKOswUE731c)。
简而言之,我有一个有3个视图的故事板;受保护的vc,登录vc和RegisterViewController。我设置了2个segues
segue modal with protected_vc< - > login_vc用loginView标识
在login_vc< - >按钮上的segue模式用registerView
标识的RegisterViewController
我在登录vc上使用注册按钮时遇到问题。如果我单击注册按钮,它会崩溃应用程序并收到消息'Receiver (<registerLogin.RegisterViewController: 0x7f97235f6140>) has no segue with identifier 'loginView''
现在我注意到在教程中选择一个segue给出另一个下拉列表,在我的情况下我只看到push - modal -popover - replace和custom。这可能是原因??
或者这部分ViewController
override func viewDidAppear(animated: Bool) {
self.performSegueWithIdentifier("loginView", sender: self);
}
RegisterViewController的完整代码是
import UIKit
class RegisterViewController: ViewController {
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var repeatPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func registerButtonTapped(sender: AnyObject) {
let userEmail = userEmailTextField.text
let userPassword = userPasswordTextField.text
let repeatPassword = repeatPasswordTextField.text
//No empty fields
if((userEmail!.isEmpty || userPassword!.isEmpty || repeatPassword!.isEmpty)){
//Display alert message
displayMyAlertMessage("All fields required")
return
}
//Check if passwords match
if(userPassword != repeatPassword){
//Display alert message
displayMyAlertMessage("Passwords mistakes")
return
}
//Store data
NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey: "userEmail")
NSUserDefaults.standardUserDefaults().setObject(userPassword, forKey: "userPassword")
NSUserDefaults.standardUserDefaults().synchronize()
//Display alert message with confirmation
let myAlert = UIAlertController(title: "Alert", message: "Registration successful", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { action in
self.dismissViewControllerAnimated(true, completion: nil)
}
}
func displayMyAlertMessage(userMessage:String){
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
}
}
和完整的错误消息(手动换行第一行):
2015-10-11 07:17:57.378 registerLogin[667:10462] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<registerLogin.RegisterViewController: 0x7fb7f978d4c0>)
has no segue with identifier 'loginView''
*** First throw call stack:
(
0 CoreFoundation 0x0000000102d249b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104923deb objc_exception_throw + 48
2 UIKit 0x00000001036caba3 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
3 registerLogin 0x0000000102b4260f _TFC13registerLogin14ViewController13viewDidAppearfS0_FSbT_ + 127
4 registerLogin 0x0000000102b42661 _TToFC13registerLogin14ViewController13viewDidAppearfS0_FSbT_ + 49
5 UIKit 0x00000001036cd82e -[UIViewController _setViewAppearState:isAnimating:] + 830
6 UIKit 0x00000001036ce1b0 -[UIViewController _endAppearanceTransition:] + 262
7 UIKit 0x000000010369950e -[UIPresentationController transitionDidFinish:] + 827
8 UIKit 0x0000000103857c17 -[_UICurrentContextPresentationController transitionDidFinish:] + 42
9 UIKit 0x000000010369c97e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
10 UIKit 0x0000000103eb105c -[_UIViewControllerTransitionContext completeTransition:] + 101
11 UIKit 0x00000001036963fb -[UITransitionView notifyDidCompleteTransition:] + 252
12 UIKit 0x000000010369610c -[UITransitionView _didCompleteTransition:] + 1344
13 UIKit 0x0000000103698878 -[UITransitionView _transitionDidStop:finished:] + 104
14 UIKit 0x00000001035c3a63 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
15 UIKit 0x00000001035c3e12 -[UIViewAnimationState animationDidStop:finished:] + 80
16 QuartzCore 0x000000010799bd70 _ZN2CA5Layer23run_animation_callbacksEPv + 308
17 libdispatch.dylib 0x000000010540d4bb _dispatch_client_callout + 8
18 libdispatch.dylib 0x00000001053f53ff _dispatch_main_queue_callback_4CF + 1738
19 CoreFoundation 0x0000000102c84e69 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
20 CoreFoundation 0x0000000102c463b9 __CFRunLoopRun + 2073
21 CoreFoundation 0x0000000102c45918 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000010722dad2 GSEventRunModal + 161
23 UIKit 0x000000010354199e UIApplicationMain + 171
24 registerLogin 0x0000000102b4323d main + 109
25 libdyld.dylib 0x000000010544292d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我设置了segues
在项目中查找一个名为loginView的项目只给出2个搜索结果,看到图像,所以我没有得到RegisterViewController“认为”它需要loginView的地方
答案 0 :(得分:5)
您的班级RegisterViewController
是ViewController
的子类,但可能应该是UIViewController
的子类。可能您的ViewController
类是创建新项目时已创建的主视图控制器。
当RegisterViewController
是ViewController
的子类时,它还会继承viewDidAppear
方法。因此,当它出现时,performSegue...
会调用loginView
,但现在RegisterViewController
的实例没有loginView
segue。因此例外。
下面的原始答案,这是has no segue with identifier '...name...'
种类<例外}的可能原因:
可能您的segue标识符未设置或拼写错误。