UITableViewCell, show delete button on swipe
During startup in (-viewDidLoad or in storyboard)
do:
self.tableView.allowsMultipleSelectionDuringEditing = false
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.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
Add swipe to delete UITableViewCell
Add these two functions:
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}
Swift 3.0:
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}
Swift 4.2
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == .delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}
How to show delete button in UITableViewCell without swiping/touching it like in Moda Operandi iOS app?
The native UITableViewRowAction
does not support that, but you could write your own implementation or use a library.
e.g This one: MGSwipeTableCell,
Implement the cells and the delegate according to the documentation, then use the showSwipe
method to display the swipe actions programmatically.
How to customize the Delete button shown when swipe a UITableViewCell
there is too much solutions... you should to search before posting new question. check this link:
iOS Programming 101: How To Create Swipeable Table View Cell to Display More Options
or use ready-made solutions like this:
https://github.com/CEWendel/SWTableViewCell
i can't post much links without 10 reputation, so try to google "custom delete button uitableviewcell"
UITableViewCell show delete button on tap
I eventually ended up using: MGSwipeTableCell
Related Topics
Is There a Good Charting Library For Iphone
React Native: How to Select the Next Textinput After Pressing the "Next" Keyboard Button
Looping a Video With Avfoundation Avplayer
Move a View Up Only When the Keyboard Covers an Input Field
How to Get a Plist as a Dictionary in Swift
Cordova App Not Displaying Correctly on Iphone X (Simulator)
Nsurlconnection Using iOS Swift
Change Color of Certain Pixels in a Uiimage
How to Implement Re-Ordering of Coredata Records
Why Uitableviewautomaticdimension Not Working
How to Write Text on Image in Objective-C (Ios)
Ineligible Devices Section Appeared in Xcode 6.X.X
How to Play a Local Video With Swift
Fade/Dissolve When Changing Uiimageview'S Image
Iphone Smooth Sketch Drawing Algorithm