我有一个数组对象,我想通过一个segue并在一个连接的页面上使用。
第一页获取此数组并将其传递给segue,如下所示:
//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数组被捕获:
var peopleData:[Person]!
然而,当将它附加到UILabel时,我得到一个nil对象错误。我试图使用以下方法附加它:
headerLbl.text = peopleData[0].name
非常感谢任何帮助!
答案 0 :(得分:0)
你在哪里打电话给headerLbl.text = peopleData[0].name
。你确定你收到的nil错误是由数组为零而不是实际标签是nil触发的吗?如果您在实际显示视图之前尝试访问标签,则它将为零。