【发布时间】:2017-11-20 09:16:30
【问题描述】:
我想访问 cellForRowAt 之外的一些单元格值。
@IBAction func ShareClicked(_ sender: UIButton) -> Void {
print("Hello Edit Button")
let indexPath = IndexPath(row: 0, section: 0)
let cell = TableView.cellForRow(at: indexPath) as! ProfileTableViewCell
let activityVC = UIActivityViewController(activityItems: [cell.Books!, "I found this book", cell.Title!,"in the LitSwap app for :",cell.Price! ], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completion: nil)
}
我想在按钮功能中访问 cell.Books、cell.Title 和 cell.Price。但是,通过上面的解决方案,我希望能够捕获 tableViewCell 中的任何行,而不仅仅是 (row: 0, section: 0),但我不知道该怎么做。
【问题讨论】:
-
不要尝试访问单元格信息。这是一个视图,而不是您的数据。从您的数据模型访问您的数据。
-
@rmaddy 嗯?我该怎么做?
-
访问您在所有表视图数据源方法中使用的相同数据模型,例如
numberOfRowsInSection和cellForRowAt。 -
按照 rmaddy 的建议去做。虽然我真的不确定你的问题是什么。您知道如何访问它 row:0, section:0 ...您可以访问任何其他 indexPath ,例如行:10,部分:2...
-
@Honey 但我希望用户能够点击他们想要的任何单元格,并且通过我对行和部分进行硬编码,任何用户都无法点击他们想要的任何单元格跨度>
标签: ios swift uitableview firebase-realtime-database