代码之家  ›  专栏  ›  技术社区  ›  David.Chu.ca

在编辑模式下动态添加新行作为加载项UITableView?

  •  0
  • David.Chu.ca  · 技术社区  · 16 年前

    [self.tableView setEditing:YES animated:YES];
    

    当表视图处于编辑模式时,我想在表视图的末尾添加一行,并在左侧添加按钮作为附件。当视图不在编辑模式下时,将不显示“添加”行。这与iPhon e联系人应用程序中联系人处于编辑模式的情况非常相似。

    顺便说一下,我的表视图是从xib文件加载的。不确定是否有任何设置将表视图的样式指定为UITableViewCellEditingStyleDelete和uitableviewcelleditingstyleinsert以启用添加功能?

    1 回复  |  直到 16 年前
        1
  •  4
  •   Alfons    16 年前

    您需要实现一系列委托方法。

    - (UITableViewCellEditingStyle) tableView: (UITableView *) tableView 
    editingStyleForRowAtIndexPath: (NSIndexPath *) indexPath
    

    在UITableViewDataSource端:

    - (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle 
     forRowAtIndexPath: (NSIndexPath *) indexPath
    

    您只需向数据源添加新行,然后调用 [tableView reloadData] [tableView insertRowsAtIndexPaths:...] .

    哦。