سؤال

Ha ii everybody,i have a question ,how can we implement the swiping gesture functionality in tableview?My project have many chapters each chapter is loaded in tableview cell,i put go to next-chapter in a button-click and place it in the footer of the tableview and go to previous page button in the header of the tableview.everything went fine,it reloads data when user tap the buttons.But now i want this functionality in swipe the tableview cell,when the user swipe right it want to loads next chapter and vise versa.my code for next and prvous chapter is

-(IBAction)_clickbtntablenextchapter:(id)sender
{
    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}
-(IBAction)_clickbtntableprvchapter:(id)sender
{
    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}

I just want to implement it in swipe function. thanks in advance. edit

-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {
    // do whatever you need to do ...
    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}
-(void) handleSwipeGestureleft:(UISwipeGestureRecognizer*)recognizer {
    // do whatever you need to do ...
    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
} 
this is gesture code and my button code is ,in button it works perfect.
-(IBAction)_clickbtntablenext:(id)sender
{
    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}
-(IBAction)_clickbtntableprevious:(id)sender
{
    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}
هل كانت مفيدة؟

المحلول

The swiping behaviour is default in edit mode, you should look into Inserting and Deleting Rows in Editing Mode.

If you want to have your own behaviour you can use a UISwipeGestureRecognizer to detect the swipes.

EDIT:

Create the reconizer:

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight // or whatever
[cell addGestureRecognizer:swipeGesture];
[swipeGesture release];

Implement the callback for the target:

-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {
    // do whatever you need to do ...
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top