1

This is my app:

App image

When i press the Edit button (''Rediger''), i get the following:

This happens

So my question is: How do i make the round red circle and the disclosure indicator hidden while the tableview is being edited? Both the circle and the disclosure indicator are imageViews.

Here is the code for the custom cell (i edited out the unnecessary parts):

class KundeavisCell: UITableViewCell {

@IBOutlet weak var unreadImage: UIImageView!
@IBOutlet weak var disclosureIndicatorImage: UIImageView!

}

And the view controller with the table:

class KundeaviserVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!

@IBOutlet weak var redigerOutlet: UIBarButtonItem!

var stores = ["Rema 1000", "Coop Obs", "Coop Extra"]

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "KundeavisCell", for: indexPath) as! KundeavisCell

    // Here i edit the cell

    return cell
}

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return stores.count
}

@IBAction func tableViewEditingPressed(_ sender: Any) {

    if tableView.isEditing {
        tableView.setEditing(false, animated: true);
        redigerOutlet.style = UIBarButtonItemStyle.plain;
        redigerOutlet.title = "Rediger";

    } else {

        tableView.setEditing(true, animated: true);
        redigerOutlet.title = "Ferdig";
        redigerOutlet.style =  UIBarButtonItemStyle.done;

    }
}

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    return true
}

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

    let itemToMove = stores[sourceIndexPath.row]
    stores.remove(at: sourceIndexPath.row)
    stores.insert(itemToMove, at: destinationIndexPath.row)
}

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return UITableViewCellEditingStyle.none
}

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

}

I know i can indent the images to the left by setting constraints on them, but i want to hide them completely. I found a question about it: Link but unfortunately it was written 5 years ago and in Objective-C.

Any help will be highly appreciated, thanks!

Community
  • 1
  • 1
  • Unfortunately I don't code in Swift. However, try subclass your UITableViewCell and override **setEditing:animated:** as mentioned in this thread: http://stackoverflow.com/questions/19678695/customising-cell-editing-style-in-uitableview-in-ios , from there you can set your ImageViews to hidden = YES/NO depending on how you edit/stop edit. –  Feb 12 '17 at 23:08
  • I wnat to know can we change the editing button to the right? – ArgaPK Jan 03 '22 at 13:51

1 Answers1

0

That code you reference is still valid to now. You already have the Custom implementation of the UITableViewCell so now implement the SetEditing function and in the implementation hide/shows your images.

override func setEditing(_ editing: Bool, animated: Bool) {
    unreadImage.isHidden = editing
    disclosureIndicatorImage.isHidden = editing
}

That should work.

pinedax
  • 9,246
  • 2
  • 23
  • 30