【发布时间】:2015-08-14 11:02:34
【问题描述】:
我的主视图中使用了一个 NSManagedObject。
在这个视图中,我有两个容器,每个容器都有自己的静态 TableView。
在我的 NSManagedObject 中,我有一个想要循环的数组,并在屏幕上显示信息,如下所示:
Customer1 Name
Customer1 Type
Customer1 Address
Customer2 Name
Customer2 Type
Customer2 Address
我尝试过使用 TableView 的路线,我添加了一个容器,将 tableview 嵌入其中,设置了一个自定义单元格并尝试用一些测试数据填充自定义单元格。当我运行它时,虽然 TableView 只显示了四个空行。 (我可能遗漏了与行数有关的东西,这就是我的测试数据没有显示的原因):
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tblPartyDetails.dequeueReusableCellWithIdentifier(
"JobViewPartyCell", forIndexPath: indexPath)
as! JobViewPartyCell
cell.lblPartyName.text = "test name"
cell.lblPartyAddress.text = "test adddress"
cell.lblPartyType.text = "test partyType"
return cell
}
我还必须弄清楚如何将我的 NSManagedObject 传递到这个 TableView 类中,对于只是重复的信息块似乎需要付出很多努力......或者......这是唯一的方法吗?
那么,我是否以正确的方式处理这件事?如果是这样,我该如何修复它并将我的 NSManagedObjects 详细信息添加到 TableView。如果我没有正确解决这个问题,还有什么替代方案?我查看了其他一些自定义“卡片”类型的东西,例如 facebook 和 google 卡片,但这些技术也使用自定义 TableViewCells。
编辑。 PrepareForSegue 函数:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == jobSegueIdentifier {
if let destination = segue.destinationViewController as? JobViewController {
if let jobIndex = tblJobs.indexPathForSelectedRow() {
let workItem:Work = fetchedResultsController.objectAtIndexPath(jobIndex) as! Work
destination.workItem = workItem
}
}
}
}
【问题讨论】:
标签: ios swift uitableview core-data