0

我正在设置所有必需的属性以UITableView在我的 iOS 应用程序中为 a 实现重新排序控件,但是未显示重新排序控件。这是代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return 4;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"DragAndDrop";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text=[[NSString alloc]initWithFormat:@"Row %d", indexPath.row];
    cell.showsReorderControl=YES;
    return cell;
}

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


-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView setEditing:YES animated:YES];
}


-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
         [tableView reloadData];
}

我已经实现了所有必需的方法。为什么不显示?

4

3 回答 3

3

为此,您需要从一开始就设置 UITableView 的“编辑”属性。

希望对您有所帮助。

干杯!

于 2013-01-29T06:17:44.683 回答
0

我忘记将故事板中的委托链接到表格视图。现在一切都很好!!

于 2013-01-29T06:33:35.943 回答
0

试试这个 。. .this 将在编辑模式下的简单表格视图的情况下处理单元格的排列和更新

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

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
     [tableData insertObject: [tableData objectAtIndex:sourceIndexPath.row] atIndex:destinationIndexPath.row];
     [tableData removeObjectAtIndex:(sourceIndexPath.row + 1)];
}
于 2013-11-04T09:46:31.157 回答