我有一個數組對象,我想通過一個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