将viewcontroller分配给prepareForSegue中的变量时,Swift EXC_BREAKPOINT [英] Swift EXC_BREAKPOINT when assigning viewcontroller to variable in prepareForSegue

查看:310
本文介绍了将viewcontroller分配给prepareForSegue中的变量时,Swift EXC_BREAKPOINT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用destinationViewController执行变量赋值时出错。

Im getting an error when trying to perform a variable assignment with my destinationViewController.

错误信息如下:
线程1:EXC_BREAKPOINT(代码= EXC_I386_BPT,子代码= 0x0)

The error message is this: Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)

这在我的prepareForSegue函数中。

This in my prepareForSegue function.

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if segue.identifier == "LoginSegue"{

        let vc = segue.destinationViewController as LoggedInViewController
        vc.email = emailTextfield.text

    }
}

在另一个文件中它看起来像这样。

In the other file it looks like this.

var email: String?

位于顶部。
然后这个:

which is at the top. Then this:

override func viewDidLoad() {
    super.viewDidLoad()

    println("Email is:")
    println(email)
    println("Email was")
}

但是我从来没有进入第二个文件。

But i never come into the second file.

这行是让vc = segue.destinationViewController为标记为错误的LoggedInViewController。

It is the line let vc = segue.destinationViewController as LoggedInViewController that is marked with error.

两个swift文件都连接到导航控制器。

Both swift files are connected to navigation controllers.

我不知道是什么你需要的更多,但我当然会发布你需要理解的所有代码!

I dont know what more you need, but I will of course post all code you need to understand!

谢谢!

推荐答案

在你的情况下,目标控制器是导航控制器而不是你的 LoggedInViewController ,所以 segue.destinationViewController as LoggedInViewController 是一个错误因此它崩溃了。

In your case destination controller is navigation controller not your LoggedInViewController , So segue.destinationViewController as LoggedInViewController is an error , therefore it is crashing.

试试这样

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if segue.identifier == "LoginSegue"{
            let navigationController = segue.destinationViewController as UINavigationController

        let vc = navigationController.topViewController as LoggedInViewController
        vc.email = emailTextfield.text

    }
}

这篇关于将viewcontroller分配给prepareForSegue中的变量时,Swift EXC_BREAKPOINT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆