tableView(_:didSelectRowAt:) still active when in edit mode

I have the "didSelectRowAt" method in my swift app so that when I tap a cell the AVPlayer plays a video associated with the cell. I'm currently trying set the table up so that the user can go into edit mode, select multiple cells, and share the videos via my UIActivityViewController. My issue is that when the table's in edit mode and I select the selection circle, it plays the video. Now, according the SD (https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614877-tableview) this shouldn't happen.


Here's my select function

func select(){
        if (self.tableView.isEditing == false){
          
            self.tableView.setEditing(true, animated: true)
        }
      
        else{
      
            self.tableView.setEditing(false, animated: true)
          
        }
    }


and my cell selection method

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      
        let index = tableView.indexPathForSelectedRow
        let videoStrings = self.videoSTRINGS
        let indNum = index!.row
        let videoNum = videoStrings[indNum]
        let video = URL(string: videoNum)
        self.avPlar = AVPlayer(url: video!)
        self.avPlarCon.player = avPlar
        self.present(self.avPlarCon, animated: true){
            self.avPlarCon.player!.play()
        }
       
    }



Any help is much apprecciated.

Accepted Reply

When reading documentation, we should not go here if it is true.

The only reason I could imagine would be that you call

func selectRow(at indexPath: IndexPath?, animated: Bool, scrollPosition: UITableViewScrollPosition)

elsewhere in code.

But even this should not call didselectrow if in editing mode!

If not, I would file a bug on this specific point: how can the delegate func be called when isEditing is true.

Replies

Can you show how select() is called ? Is it called independantly of didSelectAtRow ?


you could shorten the writing of select (but may be less readable):


func select() {

self.tableView.setEditing( !self.tableView.isEditing, animated: true)

}

I call the function through an IBAction button. Basically:


@IBAction select (sender: UIButton){
select()
}


So to answer the question, yes. It is called independantly of didSelectRowAt.

I tested in an app Xcode 7.3 and 8.3.


At the end of viewWillAppear, I forced

self.tableView.setEditing(true, animated: true)


When the table shows, each cell has a red spot with minus sign on the left to allow for deleting a cell. (Is it what you call selection circle ?)

And does nothing if I click in the cell out of the red dot.

I'm using the latest version of Xcode (8.3 I think). The selection circle I'm talking about is simply a checkmark on the left side of the cell. When you force it like that, isn't it always in edit mode though? I have to be able to cycle in and out. Could it be that it's because the didSelectRowAt is override?

Yes, the checkmark red circle on the left only appear if tavle is set editing. And then, clicking elsewhere in the cell is disabled.


What do you mean precisely by "I have to be able to cycle in and out" I thought that was the purpose of your select button.


I probably miss something in your goal.

It's just a little confusion. I misunderstood the context of your reply. The select button is meant to cycle in and out of edit mode, and I already understood that the checkmark is only visible in edit mode. My goal is to figure out why in the world is it still playing the video while the table's in edit mode. As I stated originally, according to the Swift Documentation, the didSelectRowAt method is disabled when the Table is in edit mode, yet it's still activated while it is in edit mode.

It is always difficult to understand each other precisely.So, let me check each part. Stop me if misunderstood.


The select button is meant to cycle in and out of edit mode

I understand this is working, when you click the button, outside tableView, the view goes on edit or non edit mode, and the circles appear or dispapear


My goal is to figure out why in the world is it still playing the video while the table's in edit mode

Was video already going on when you click button to go in edit mode and just continue to play ? That's would be logic

or does the video start to play when you click on cell while in editing mode ? That would be more surprising

You're spot on all the way. The way it's setup you can't go into edit mode while the video's playing, because it switches to the AVPlayer. My issue is that the video starts to play when I click on the cell while I'm in editing mode. So yeah, very suprising.

Can you check (with a log) that didSelectRowAt is effectively called when you click on cell whilst in editing mode ?

The computer with the project isn't with me right now. So I'm going to have to get back to you this evening (my time zone 😝) with an answer.

My time zone is France, which time zone is land of free ? 😉

I'm in California. So you had dinner a couple of hours ago, and I'm just about to have lunch😀. It also means that I'm talking with someone in the future😁. So what is the future like?

Yes, and good old french dinner !


What I can tell, sitting in front of my computers, is that future is not yet bug free, but great anyway.

Ratatouille?

nearly. Piperade.