How to disable editing UITableViewController in Popover

Alexey Milahin

I turn on the editing table in the FirstViewController

@IBAction func editButtonPressed(sender: UIBarButtonItem) {
     self.tableView.allowsMultipleSelectionDuringEditing = true
     if self.editing {
          let popoverEditMenu = self.storyboard?.instantiateViewControllerWithIdentifier("popoverEditMenu") as! EditMenuTableViewController
          popoverEditMenu.modalPresentationStyle = .Popover
          popoverEditMenu.popoverPresentationController!.delegate = self
          let popover: UIPopoverPresentationController = popoverEditMenu.popoverPresentationController!
          popover.barButtonItem = sender
          presentViewController(popoverEditMenu, animated: true, completion: nil)
      } else {
          editButton.image = UIImage(named: "profile_more")
          self.editing = !self.editing
      }
}

Editing table is included successfully. After the above actions, I want to finish editing, by clicking on a table cell in a popover, code:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let firstTableVC = self.storyboard?.instantiateViewControllerWithIdentifier("firstTableVC") as! FirstTableViewController

    tableView.deselectRowAtIndexPath(indexPath, animated: true)
    switch indexPath.row {
    case 0:
        self.dismissViewControllerAnimated(true, completion: nil)
        firstTableVC.editing = false // Disable Editing
        firstTableVC.editButton.image = UIImage(named: "1461294921_15.Pencil")
    default:
        break
    }
}

But there is no change in the button image, and table editing mode not disabled

Alexey Milahin

Solution found!

The problem was solved by the use of delegation. Thanks to @pbasdf for the tip

import UIKit

protocol SecondTableViewControllerDelegate {
    func endEditing()
}

class SecondTableViewController: UITableViewController {

    var delegate: SecondTableViewControllerDelegate?

    ...

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        switch indexPath.row {
        case 0:
            self.dismissViewControllerAnimated(true, completion: nil)
            delegate?.endEditing()
        default:
            break
        }
    }
}

Delegate function in FirstViewController. You need to specify a delegate inheritance in FirstViewController

func endEditing() {
    self.editing = false
    editButton.image = UIImage(named: "1461294921_15.Pencil")
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do we disable editing options on JDateChooser?

How to disable editing my history in bash

How to disable editing in a cell according to the value in another cell in Apache POI?

How can I disable editing cells in a WPF Datagrid?

How to disable editing of elements in combobox for c#?

How to disable UITextField editing but still accept touch?

Disable editing in NSTextView

Disable editing of a text field

How can I dynamically disable popover from a DOM element?

Ionic v2 - How to disable popover animation

How to disable editing a UITextField which uses a UIPickerView as inputView

How to disable RTL support in Android Studio (editing source code)?

How to disable autofocus of multiple material-ui popover windows?

Tabulator. How to enable and disable editing from js

How to disable animation when popover dismiss on Ionic 4

How to disable editing of React-Table jump page input?

disable ngx-bootstrap popover?

Any way to disable popover dragging?

TextEditor disable editing

Disable editing account info

How to disable Save Handler on Jqgrid while doing editing

UITableViewController and NSFetchedResultsController Editing Issues

Disable editing in wxWidgets listctrl

How to disable the key 'V' in VI Editing Mode against bash

How to disable/enable sorting while editing in Angularjs

How can I disable editing content inside a column on my DataGrid

How to disable cell editing in VB.Net data grids?

How to remove row in UITableViewController presented as popover

How to disable editing registry by standard user in Win 7