如何在两个表视图之间传递数据?我有poet.plist
个有2个数组:name
和biography
。当我运行应用程序时,第二个表视图为空。第一个表视图应列出诗人,而第二个表视图列出诗人的作品。
头等舱
class Poets
{
var poetName:String = ""
var poetImage:String = ""
var books=[Works]()
}
第二课:
class Works {
var nameWork = ""
var workPoet = ""
init(nameWork: String, workPoet: String) {
self.nameWork = nameWork
self.workPoet = workPoet
}
}
第一视图控制器
let worksArray = booksDict[poet.poetName as String] as! NSArray
for work in worksArray {
let dictionaryFromArray = work as! NSDictionary
let workObject = Works(nameWork: dictionaryFromArray["nameWork"] as! String, workPoet: dictionaryFromArray["work"] as! String)
poet.books.append(workObject)
}
如何在诗人姓名的UITableViewController
和诗人的作品UITableViewController
之间划一句话?
答案 0 :(得分:2)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// ShowPoetWorks is your segue identifier which you can set in storyboard
if segue.identifier == "ShowPoetWorks" {
var secondVC = segue.destinationViewController as? SecondViewController
secondVC.poetName = poetName
}
}
poetName
和workCount
覆盖函数`tableView:numberOfRowsInSection
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return workCount
}
tableView.reloadData()