ios - 接收器没有带有标识符错误消息的 segue

标签 ios segue

我正在使用 xcode 7 beta 和 swift 2.0。我正在学习教程 (youtube.com/watch?v=PKOswUE731c)。

简而言之,我有一个有 3 个 View 的 Storyboard;一个 protected vc、一个登录 vc 和 RegisterViewController。我已经设置了 2 个 segues

segue modal with protected_vc <-> login_vc identified with loginView

segue modal on a button in login_vc <-> RegisterViewController identified with registerView



我在登录 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);
    }

enter image description here

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

我已经设置了segue

enter image description here

并从注册按钮
enter image description here

在项目中查找术语 loginView 只提供 2 个搜索结果(见图像),所以我不明白 RegisterViewController“认为”它需要 loginView 的地方

enter image description here

最佳答案

您的类(class) RegisterViewControllerViewController 的子类,但可能应该是 UIViewController 的子类.可能是你的 ViewController class 是创建新项目时已经创建的主 View Controller 。

RegisterViewControllerViewController 的子类,它还继承了viewDidAppear方法。因此,当它出现时,它会调用 performSegue...loginView ,但现在有了 RegisterViewController 的实例没有loginView赛格。因此异常(exception)。

下面的原始答案,这可能是此类异常的原因 has no segue with identifier '...name...' :

可能您的 segue 标识符未设置或拼写错误。

Segue ID

  • 点击转场
  • 确保右侧的“实用工具”面板可见
  • 确保属性检查器可见
  • 检查“Storyboard Segue”下的“Identifier”值(在屏幕截图中为“infoSegue”)
  • 关于ios - 接收器没有带有标识符错误消息的 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33057818/

    相关文章:

    ios - 通过动态原型(prototype)中的 segue 传递 myCell.textLabel?.text 值

    ios - UIAlertController 阻止 segue 执行 ("window is not equal to view’ s 窗口“)

    ios - 为什么我的 UIView 的一部分覆盖了键盘?

    ios - UIWebView request.response = nil 问题

    iphone - EAGLView 到 UIImage 的时序问题

    ios - Xcode 6在打开使用Popover Segue的 Storyboard时崩溃

    ios - 一个segue来统治他们

    ios - 具有大量图像的 UITableView

    ios - 将 Objective-C 方法转换为 Swift for NSInputStream(将字节转换为 double )

    ios - 以编程方式展开 segue