I'd like to swipe the cell to the left and display the Delete button and the Details button to delete the cell and transition to the Details page.
The Delete button successfully wrote the following code:
functableView(_tableView:UITableView, commit editingStyle:UITableViewCellEditingStyle, forRowAtindexPath:IndexPath){
ifeditingStyle==.delete{
dataList.remove(at:indexPath.row)
testTableView.deleteRows(at:[indexPath], with:.fade)
} }
However, I don't know how to attach the detail button and the code of the screen transition when I press the detail button.
The ideal completion diagram is the following image.
Thank you for your cooperation.
swift tableview
Use the tableView(_:editActionsForRowAt:)
method of UITableViewDelegate
. See the reference for the UITableViewRowAction
class.
I will list the sample code.Table configuration is a prerequisite on the Storyboard.
import UIKit
classViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
functableView(_tableView:UITableView, numberOfRowsInSection section:Int) - > Int{
return12
}
// UITableViewDataSource
functableView(_tableView:UITableView, cellForRowAtindexPath:IndexPath) - >UITableViewCell{
letcell=tableView.dueReusableCell(withIdentifier: "Cell", for:indexPath)
cell.textLabel?.text="No.\(indexPath.row)"
return cell
}
// UITableViewDelegate
functableView(_tableView:UITableView, editActionsForRowAtindexPath:IndexPath)->[UITableViewRowAction]?{
let action = UITableViewRowAction(style:.default, title: "Detail") {action, indexPath in
// Do anything
}
return [action]
}
}
//Do Anything
describes what happens when you tap the button.
© 2024 OneMinuteCode. All rights reserved.