0

大家好,我有一个问题,我们如何在 tableview 中实现滑动手势功能?我的项目有很多章节,每章都加载到 tableview 单元格中,我通过单击按钮转到下一章并将其放在表格视图的页脚并转到表格视图标题中的上一页按钮。一切正常,当用户点击按钮时它会重新加载数据。但是现在我希望这个功能在滑动表格视图单元格时,当用户向右滑动它想要加载下一章,反之亦然。我下一章和上一章的代码是

-(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]; 
}

我只想在滑动功能中实现它。提前致谢。编辑

-(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]; 
}
4

1 回答 1

4

滑动行为是编辑模式下的默认行为,您应该查看Inserting and Deleting Rows in Editing Mode

如果您想拥有自己的行为,可以使用 UISwipeGestureRecognizer 来检测滑动。

编辑:

创建reconizer:

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

实现目标的回调:

-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {
    // do whatever you need to do ...
}
于 2011-11-10T09:45:27.653 回答