Abhijeet Abhijeet - 5 months ago 34
Swift Question

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. 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? 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 {

        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() {