Swipe left/right to push next/previous details view
- by Youssef
I am working on a ios application, using storyboard.
I have a simple table view with rows. Each row has a "key" string to identify it. When the user clicks on a row I push the next view "DetailsViewController" and pass the "key" as a parameter in the prepareForSegue method. The data in the second view will change based on the "key" passed.
In the "DetailsViewController" I want to add a swipe gesture, when the user swipes right, I want to push the next details view. It will be as if he clicked on the next row in the table view. So to rephrase, the user has 2 ways of switching between items: he can click the item in the table view and the details view will show, he can then go back and select another item.
Or he can click on a row, and in the details view he can swipe left and right to see the previous/next item.
i added the uigesture recognizer:
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:recognizer];
- (void) handleSwipe:(UISwipeGestureRecognizer *) sender
{
//I want to go to the next item in the tableview
}
I hope I was clear.
Thank you.