【发布时间】:2014-06-26 20:43:45
【问题描述】:
我正在开发一个功能,比如在表格视图中为不同的行拖放单元格。我将第一项拖动到最后一项并将行滚动到表格视图的顶部。它在 iOS 7.1 版本之前运行良好,但是当我使用 iOS 8 beta 模拟器测试相同的代码库时,拖动按钮消失了,我无法再拖动单元格了。这是我的示例代码供您参考。
- (void)viewDidLoad
{
[super viewDidLoad];
list = [[NSMutableArray alloc]initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15",@"16", nil];
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [list count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"DragCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
cell.showsReorderControl = YES;
}
cell.textLabel.text = [list objectAtIndex:indexPath.row];
return cell;
}
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
NSInteger sourceRow = sourceIndexPath.row;
NSInteger destRow = destinationIndexPath.row;
id object = [list objectAtIndex:sourceRow];
[list removeObjectAtIndex:sourceRow];
[list insertObject:object atIndex:destRow];
}
如果你们在 iOS 8 中遇到同样的问题,请告诉我。
【问题讨论】:
-
你真的应该在 iOS 8 beta 的开发者论坛上解决这些问题...
-
我可以拖动表格视图中的所有行。不过,我还有另一个问题:Described here 当这种情况发生时,重新排序按钮会消失。
-
Nikita,如果超过 10 行,请尝试在删除后向上或向下滚动?