Abhijeet Abhijeet - 1 year ago 92
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?

Answer Source

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() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download