Hit the code when you encounter this problem, do not lazy, write down for reference.
When you are in IB to TableView in the accessory (note, I said the cell accessory, not the cell) to create segue, if you in the VC at the same time implement the following 3 methods, call the Order is God horse!?
//1func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath)//2overrideString, sender: Any?) -> Bool//3override func prepare(for
The answer is: 2,1,3
If you use Shouldperformsegue, then you cannot take the segue itself in the method, you must cooperate with the Prepare method.
If you need to get the index of the cell that was pressed accessory in the Prepare method, then you cannot use Tableview.indexpathforselectedrow, Because you segue bind the cell's accessory instead of the cell, the return value you get is nil.
To solve the above problem is very simple prepare the second parameter sender is:
letas! UITableViewCelllet selectedRow = tableView.indexPath(for: cell)!.row
If you are customizing the cell's Accessory button, you may need to return to the following method:
tableView.indexPathForRow(atpoint)
Here is the equivalent of the OBJC code, leaving a thought:
*touches = [event allTouches]; *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.contactsTableView];
TableView the timing of the Accessorybuttontappedforrow method execution