繁体   English   中英

重新排列UITableView行-fromIndexPath和toIndexPath相同

[英]Rearranging UITableView rows - fromIndexPath and toIndexPath the same

我在重新排列tableView的行时遇到麻烦。 该表处于编辑模式,并且所有相关方法都被覆盖以返回YES

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
    NSLog(@"From: %d to: %d", fromIndexPath.row, toIndexPath.row);
    // some code to modify the dataSource
    // ...
}

发生的是,在显示重新排列控件时,如果我尝试拖动它,它只会将行移动一点,然后moveRowAtIndexPath:toIndexPath:并且fromIndexPathtoIndexPath都相同!

经过进一步检查,似乎有时我会设法快速向上或向下滑动行以使其实际起作用,但一次只能将其移动1行。

我有另一个应用程序,可以在其中缓慢而轻松地重新排列行,但是在这里,一旦我开始拖动,它似乎想在几分之一秒后提交更改,因此,如果我没有将其移得足够远,它会跳回到它的原始行。 是什么原因造成的?

经过仔细考虑,我意识到此问题是由于应用程序的UI层而不是tableView配置引起的。 罪魁祸首是我添加到应用程序的侧面菜单模块,默认情况下会添加UIGestureRecognizer来检测用户何时滑动屏幕以显示侧面菜单。 它干扰了tableView默认手势识别器,并且一旦禁用,一切都会正常。 使用第三方库时请注意这些不良副作用:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM