【问题标题】:Deleting row by tag按标签删除行
【发布时间】:2011-12-20 14:22:07
【问题描述】:

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

当标签为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];

    }

【问题讨论】:

  • 我不明白您要删除什么“行”。还要删除NSInteger *row 上的* 我相信这会给您带来一些警告。
  • 我有多个单元格,每个单元格都有一个 ui 按钮。 uibutton 的标签设置为单元格的 indexpath.row。当这个函数被调用时,我不想为那个单元格设置动画。

标签: ios xcode uitableview tags


【解决方案1】:

UITableViewbuilt-in capabilities to allow the deletion 行。这可能更适合您想要完成的任务。这是example

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

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];

【讨论】:

  • 我知道。但我正在尝试使用 UIButton 和图像制作一个自定义复选框。当检查“复选框”时,我希望行才能fadeout(出现在“已完成的”部分) span>
猜你喜欢
  • 1970-01-01
  • 2013-05-02
  • 2014-07-23
  • 2013-12-09
  • 2018-11-09
  • 2019-12-21
  • 2020-12-07
  • 1970-01-01
  • 2014-07-16
相关资源
最近更新 更多