Cocoa touch 编辑和删除按钮UITableView

Cocoa touch 编辑和删除按钮UITableView,cocoa-touch,uitableview,Cocoa Touch,Uitableview,我可以将UITableView置于编辑模式并显示删除按钮。如何在删除按钮旁边添加蓝色的“编辑”按钮 就像在ios6中在邮件中向左滑动一样,除了邮件应用程序显示“更多”,我想要一个“编辑”按钮 这不是苹果UITableViewCell的标准功能-您需要使用自己的刷卡识别器创建自己的UITableViewCell子类 这是一个很好的开始-使用它,您应该能够使用以下代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRo

我可以将UITableView置于编辑模式并显示删除按钮。如何在删除按钮旁边添加蓝色的“编辑”按钮


就像在ios6中在邮件中向左滑动一样,除了邮件应用程序显示“更多”,我想要一个“编辑”按钮

这不是苹果
UITableViewCell
的标准功能-您需要使用自己的刷卡识别器创建自己的
UITableViewCell
子类

这是一个很好的开始-使用它,您应该能够使用以下代码:

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

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        NSMutableArray *rightUtilityButtons = [NSMutableArray new];

        [rightUtilityButtons sw_addUtilityButtonWithColor:
                    [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0]
                    title:@"More"];
        [rightUtilityButtons sw_addUtilityButtonWithColor:
                    [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] 
                        title:@"Delete"];

        cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                    reuseIdentifier:cellIdentifier 
                    containingTableView:_tableView // For row height and selection
                    leftUtilityButtons:nil 
                    rightUtilityButtons:rightUtilityButtons];
        cell.delegate = self;
    }
...

return cell;
然后为单元格实现委托方法:

- (void)swippableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
            NSLog(@"More button was pressed");
            break;
        case 1:
        {
            // Delete button was pressed
            NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];

            [_testArray removeObjectAtIndex:cellIndexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[cellIndexPath] 
                    withRowAnimation:UITableViewRowAnimationAutomatic];
            break;
        }
        default:
            break;
    }
}

这不是苹果
UITableViewCell
的标准功能-您需要使用自己的刷卡识别器创建自己的
UITableViewCell
子类

这是一个很好的开始-使用它,您应该能够使用以下代码:

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

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        NSMutableArray *rightUtilityButtons = [NSMutableArray new];

        [rightUtilityButtons sw_addUtilityButtonWithColor:
                    [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0]
                    title:@"More"];
        [rightUtilityButtons sw_addUtilityButtonWithColor:
                    [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] 
                        title:@"Delete"];

        cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                    reuseIdentifier:cellIdentifier 
                    containingTableView:_tableView // For row height and selection
                    leftUtilityButtons:nil 
                    rightUtilityButtons:rightUtilityButtons];
        cell.delegate = self;
    }
...

return cell;
然后为单元格实现委托方法:

- (void)swippableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
            NSLog(@"More button was pressed");
            break;
        case 1:
        {
            // Delete button was pressed
            NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];

            [_testArray removeObjectAtIndex:cellIndexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[cellIndexPath] 
                    withRowAnimation:UITableViewRowAnimationAutomatic];
            break;
        }
        default:
            break;
    }
}

UITableViewCell
不支持此功能。你需要自己动手。请参阅“确定”,谢谢您的链接。
UITableViewCell
不支持此功能。你需要自己动手。请参阅Ok,谢谢链接。