[英]Is it possible to add a tick mark(image) to my TableView cell when a button is tapped in other screen after tableView didselect method?
I have a tableview which Contains 10 cell named one to ten respectively.我有一个包含 10 个单元格的 tableview,分别命名为 1 到 10。 When I select a cell a new screen opens which contains a button.当我选择一个单元格时,会打开一个包含按钮的新屏幕。 I want to know is it possible when I tap that button the tableView cell related to that button gets a tick mark image?我想知道当我点击该按钮时,与该按钮相关的 tableView 单元格是否有可能获得刻度标记图像? if yes then how?如果是,那么如何?
By "new screen" do you mean a new view controller? “新屏幕”是指新的视图控制器吗? You can do it by the Delegate pattern.你可以通过委托模式来做到这一点。
protocol MainViewControllerDelegate {
func buttonOnClick(indexPath: NSIndexPath)
}
class MainViewController: UIViewController, MainViewControllerDelegate {
func buttonOnClick(indexPath: NSIndexPath) {
guard let cell = tableView.cellForRowAtIndexPath(indexPath) else {
return
}
cell.accessoryType = .Checkmark
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let newViewController = NewViewController()
newViewController.delegate = self
newViewController.indexPath = indexPath
self.presentViewController(newViewController, animated: false, completion: nil)
}
}
class NewViewController: UIViewController {
var delegate: MainViewControllerDelegate!
var indexPath: NSIndexPath!
func buttonOnClick() {
delegate.buttonOnClick(indexPath)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.