User interactions on table cells don’t have to be necessarily restricted to simply scroll and tap them. However, with some additional code and the support of gesture recognizers introduced in iOS 3.2 you can give your users the possibility to swipe on your table view cells for exciting additional actions. A common task for that would be to implement a swipe gesture for removing a single item within your table view (seen on several task management and todo apps) or simply changing the state of an item.
All you need is some pretty forward code like the following, which basically creates two gesture recognizers to handle left and right swipes on your table. As you can see we add these gesture recognizers directly to a UITableView
rather than to single UITableViewCells
.
The called methods of the gesture recognizers look like as stated below. From the gesture recognizer you’ll get the point of the start of the swipe gesture and with the indexPathForRowAtPoint:
method you can get the correct index path for the UITableViewCell
the swipe was performed on. From this point on it is up to you to perform more functionality to your table view cell.
Leave a Reply