Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SWIFT-如何传递所有数据?_Ios_Iphone_Swift - Fatal编程技术网

Ios SWIFT-如何传递所有数据?

Ios SWIFT-如何传递所有数据?,ios,iphone,swift,Ios,Iphone,Swift,我有一个数组对象,我想通过一个序列并在连接的页面上使用 第一页获取此数组并将其通过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", a

我有一个数组对象,我想通过一个序列并在连接的页面上使用

第一页获取此数组并将其通过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

任何帮助都将不胜感激

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

调试时间到了,请参阅。添加代码排列设置
UILable
。同时,打印
peopleData
以验证数据是否存在。如果未在
prepareforsgue
中打印
peopleData
。您在哪里声明personInfo?另外,请仔细检查序列标识符的拼写。也许可以在设置目标的
peopleData
的位置添加断点或日志消息,并确保到达该行代码。非常感谢您的回复。经过一点调试后,它现在在一个卡盘中传递数据。再次感谢大家