【问题标题】:iOS 8 drag and drop issue in tableview celliOS 8 在 tableview 单元格中拖放问题
【发布时间】: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 行,请尝试在删除后向上或向下滚动?

标签: ios ios8


【解决方案1】:

我可以确认。我有一个可以手动排序的带有 Cells 的 Tableview。在 iOS8b2 上没有重新排序按钮!

【讨论】:

  • 我发现如果没有“ -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath, 重新排序控件将不会出现" 实现了,即使你在这里什么都不做!!
【解决方案2】:

我发现如果没有重新排序控件就不会出现

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

实现了,即使你在这里什么都不做!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    相关资源
    最近更新 更多