我有一个数组对象,我想通过一个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
任何帮助将不胜感激!
现在是调试的时候了,请看[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
你在哪里声明personInfo? – 2015-02-05 13:13:17
另外,请仔细检查segue标识符的拼写。也许在设置目的地的'peopleData'的地方添加一个断点或日志消息,并确保你有这一行代码。 – Rob 2015-02-05 14:13:51