TableView with RightSwipe options like Gmail
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Mycell", for: indexPath) as! CustomCell
let item = data[indexPath.row]
// Add swipe gesture recognizer to the cell
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe))
swipeRight.direction = .right
cell.addGestureRecognizer(swipeRight)
// Configure the cell
cell.titleLabel.text = item.title
cell.descriptionLabel.text = item.description
return cell
}
@objc func handleSwipe(gesture: UISwipeGestureRecognizer) {
if gesture.direction == .right {
// Get the index path of the cell that was swiped
let indexPath = tableView.indexPathForRow(at: gesture.location(in: tableView))
// Perform custom actions based on the swipe
// For example, show the swipe options, mark as read, flag, or delete
}
}
Comments
Post a Comment