【问题标题】:Delete records of a TableView inside a UIView删除 UIView 中 TableView 的记录
【发布时间】:2011-12-24 11:30:12
【问题描述】:

我正在尝试在 Storyboard 的 UIView 中实现 TableView。 这就是我所取得的成就:

现在我希望编辑按钮(如果按下)准备删除表行。 我将编辑按钮放在栏上,如下所示:

//add edit button
[buttons addObject:self.editButtonItem];

此外,我已将 tableview 委托和数据源设置为主视图并触发事件。但是如何告诉编辑按钮表格的行必须是可删除的?

提前谢谢你, 亚萨

【问题讨论】:

    标签: ios uitableview button uiview edit


    【解决方案1】:

    有这个委托的tabelView方法:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:UITableViewRowAnimationFade];
        //some other bookkeeping stuff
    }
    

    添加了按下时编辑按钮的代码。将“toggleEdit”重命名为适合您需要的任何名称。

    - (IBAction)toggleEdit:(id)sender   //this method should get called when Edit is pressed
    {
        [self.tableView setEditing:!self.tableView.editing animated:YES];
    
    
    //The if ... else part is optional.  You might need to make some change to fit your's.
    //    if (self.tableView.editing)
    //        [self.navigationItem.rightBarButtonItem setTitle:@"Done"];
    //    else
    //        [self.navigationItem.rightBarButtonItem setTitle:@"Delete"];
    }
    

    【讨论】:

    • 感谢您的回答。我已经实现了委托方法。我的问题是我不知道如何将“编辑”按钮引用到我的视图中的表格...
    猜你喜欢
    • 1970-01-01
    • 2017-10-13
    • 2021-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多