简体   繁体   English

Swift Segue传递零字符串

[英]Swift segue passing nil string

Well, in my app i have to set the value of another view var, but it seems that the val i assign this var is null when it passes through the segue, the code: 好吧,在我的应用程序中,我必须设置另一个视图var的值,但是当它通过segue时,分配给该var的val似乎为null,代码为:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!)
{
    if segue.identifier == "DetailSegue"
    {
        let detailViewController = ((segue.destinationViewController) as RowViewController)
        let indexPath = self.table!.indexPathForSelectedRow()!
        detailViewController.string = name.text
    }
}

and in the second view i have something like this: 在第二种观点中,我有这样的事情:

var string: String?
override func viewDidLoad() {
    super.viewDidLoad()
    descrip.text = string
    ...

Before you ask, name does have a value, but the segue seems to pass it nil :/ i really hope you guys could help me out on this one! 在你问之前,名字确实有价值,但是segue似乎没有价值:/我真的希望你们能帮我解决这个问题!

Basic debugging for a problem like this: 针对此类问题的基本调试:

Step 1: 第1步:

Check if the storyboard segue has the same identifier as the one you put in your code. 检查情节提要Segue是否具有与您在代码中输入的标识符相同的标识符。 Remember, lower case and upper case letters do matter. 请记住,小写和大写字母都很重要。

Step 2: 第2步:

Use plenty of println()s. 使用大量的println()。 This is one of the most useful, simple debugging tools in Xcode. 这是Xcode中最有用,最简单的调试工具之一。 You can print the values of your beginning label, your string on the next view controller, etc. Before you ask questions on Stack Overflow, try to figure it out for yourself -- that will make you a better programmer, and make you not have to rely on online communities as much. 您可以在下一个视图控制器上打印开始标签的值,字符串等。在对Stack Overflow提出问题之前,请尝试自己弄清楚-这将使您成为一个更好的程序员,并且没有尽可能多地依赖在线社区。

Step 3: 第三步:

Test out some other, simpler tasks with your problem to see if it is really a bug in Xcode or a mistake. 针对您的问题测试其他一些更简单的任务,以查看它是否确实是Xcode中的错误或错误。 Example, try to assign the value you are changing on the next view controller to a static piece of text instead of a label's text. 例如,尝试将在下一个视图控制器上更改的值分配给静态文本而不是标签文本。

Hope this helped, and that you've fixed your problem. 希望这对您有所帮助,并且您已解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM