TableView with RightSwipe options like Gmail

Solution:

The below code can be used for rightswipe implementation in swift tableviewcell.

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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift