2015-02-05 48 views
-1

我有一个数组对象,我想通过一个segue并在一个连接页面上使用。SWIFT - 您如何通过所有数据?

第一页借此阵列和使其通过SEGUE如下:

var peopleData:[Person]! 

然而,它附连到时:

//home.swift 
//Data to pass through 
let personInfo:[Person] = [Person(name: "Jess", admin: "jess17", image: "jess17.png", age:"20"), Person(name: "Matt", admin: "matty101", image: "matty101.png", age:"23"), Person(name: "Tom", admin: "thomas9", image: "thomas9.png", age:"21")] 

//Segue information 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == "openAccount" { 
     let indexPath = voteCollectionView!.indexPathForCell(sender as CollectionViewCell) 
     let destinationController = segue.destinationViewController as AccountPageViewController 
     destinationController.peopleData = personInfo 
    } 
} 

在AccountPageViewController的personData阵列由被抓UILabel我得到一个零对象错误。我试图附加使用:

headerLbl.text = peopleData[0].name 

任何帮助将不胜感激!

+0

现在是调试的时候了,请看[this tuts](http://code.tutsplus.com/tutorials/debugging-in-ios-essential-tips--mobile-13705)。添加代码排列设置'UILable'。同样在这一点上打印'peopleData'来验证数据是否存在。如果它不是'prepareForSegue'中的println'peopleData'。 – zaph 2015-02-05 13:09:54

+0

你在哪里声明personInfo? – 2015-02-05 13:13:17

+0

另外,请仔细检查segue标识符的拼写。也许在设置目的地的'peopleData'的地方添加一个断点或日志消息,并确保你有这一行代码。 – Rob 2015-02-05 14:13:51

回答

0

你在哪里打电话headerLbl.text = peopleData[0].name。你确定你收到的nil错误是由数组触发的,而不是由实际的标签为零吗?如果您在视图实际显示之前尝试访问标签,则该视图将为零。

+0

非常感谢所有的回应。经过一些调试,现在将数据传递给一个卡盘。再次感谢所有人 – Lindsey 2015-02-10 14:50:00

相关问题