How do I get the delete button to show when swiping on a UITableViewCell
? The event is never raised and the delete button never appears.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
During startup in
(-viewDidLoad or in storyboard)
do:Override to support conditional editing of the table view. This only needs to be implemented if you are going to be returning
NO
for some items. By default, all items are editable.I had a problem which I have just managed to solve so I am sharing it as it may help someone.
I have a UITableView and added the methods shown to enable swipe to delete:
I am working on an update that allows me to put the table into edit mode and enables multiselect. To do that I added the code from Apple's TableMultiSelect sample. Once I got that working I found that my swipe the delete function had stopped working.
It turns out that adding the following line to viewDidLoad was the issue:
With this line in, the multiselect would work but the swipe to delete wouldn't. Without the line it was the other way around.
The fix:
Add the following method to your viewController:
Then in your method that puts the table into editing mode (from a button press for example) you should use:
instead of:
This means that multiselect is only enabled when the table is in editing mode.
Swift 4
This code shows how to implement the delete.
Optionally, in your initialization override, add the line below to show the Edit button item:
Note: I don't have enough reputation to post a comment in the answer from Kurbz.
The answer from Kurbz is right. But for me it never worked.
After some investigation, I realized that swipe-to-delete happens when NOT editing the table view..
I never seen this explicitly stated as such. Unless I'm mistaken, I haven't found any other way to have it work.
When you are editing, the delete and/or reorder control will show up.