ios - 按标签删除行

标签 ios xcode uitableview tags

我目前正在尝试创建一种 tasktracker.. 以下代码当前有效,但我需要它来删除带有按钮标签的行.. 换句话说。

当按下标签为0的按钮时,删除标签为0的行

我所有的尝试都失败了,所以我把它带给专家。

 - (void)buttonPressedAction:(id)sender
    {
        UIButton *button = (UIButton *)sender;
        NSInteger *row = button.tag;
        NSString *cleanedUp = [NSString stringWithFormat:@"%d", row];
            if(button.titleLabel.text == @"Unchecked"){
            [button setTitle:@"Checked" forState:UIControlStateNormal];
        }
        else{
            [button setTitle:@"Unchecked" forState:UIControlStateNormal];
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:button.titleLabel.text 
                                                        message:cleanedUp
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }

最佳答案

UITableViewbuilt-in capabilities to allow the deletion的行。这可能更适合您想要完成的目标。这是一个 example .

要使用自定义按钮,您需要使用 beginUpdatesendUpdates 来修改您的表格 View 动画。

NSInteger row = button.tag;
[tableView beginUpdates];
//make sure you remove the row from your datasource 
//as well or an exception will be raised
[self.datasource removeObjectAtIndex:row]
[deleteRowsAtIndexPaths:[NSIndexPath indexPathForRow:row inSection:0]
       withRowAnimation:UITableViewRowAnimationFade];

[tableView endUpdates];

关于ios - 按标签删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7985592/

相关文章:

ios - CoreML框架从coremltools生成了不同的结果

ios - 上面的 UIView 呈现 SKScene - 为什么触摸总是通过场景?

ios - 在 swift 中显示更多按钮时取消在 tableview 单元格上向左滑动

ios - UITableViewCell 未被删除

ios - 将字符串转换为 URL

iphone - 如何使用 coreGraphics 在两点连接处添加曲线?

c++ - 在 Objective-C 中使用外部 C++ 头文件

ios - UIDocumentInteractionController PresentOpenInMenuFromRect

iphone - 从 Xcode 更改按钮文本?

uitableview - 单点触控 : The correct way to reuse a UITableViewCell