【发布时间】:2016-06-05 09:45:40
【问题描述】:
我正在尝试在 tableview 和 viewcontroller 之间传递数据。 出于此处不再重复的原因,我仅通过代码以编程方式创建了视图控制器,并且在情节提要中没有任何类型的引用和存在(我在情节提要中没有 ViewController)。一切正常,图形转换也是如此,但数据转换也是如此。 在图形转换之前,我在“didSelectRowAtIndexPath”中执行了数据转换。
在视图控制器中
var purchase:Purchase?
在 TableViewController 中
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var arrayToUse:NSArray?
var tableInUse:UITableView?
let dc = DetailsViewController()
// Retrive the correct data here
let indexPath = tableInUse?.indexPathForSelectedRow
dc.purchase = arrayToUse?.objectAtIndex((indexPath?.row)!) as! Purchase
let temp = arrayToUse?.objectAtIndex((indexPath?.row)!) as! Purchase
print(temp.title)
self.navigationController!.pushViewController(DetailsViewController(), animated: true)
}
我查看了在此处和其他站点中找到的不同解决方案,但我总是找到考虑“segue”或“nib”的解决方案。 我做错了什么?
我希望我说清楚了 非常欢迎各种帮助或提示。
谢谢
【问题讨论】:
标签: ios swift uitableview uiviewcontroller