如何为TableView创建NSIndexPath

橡皮鸭

我需要在已定义的函数中删除表的第1行。为了使用,deleteRowAtIndexPath您必须使用已IndexPath定义部分和行的。我如何创建这样的索引路径?

以int {1}作为其唯一成员的数组将崩溃;NSLog消息指出该部分也需要定义。

*编辑->与单元格删除有关的代码:

    NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
    NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil];
//  [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
//  [self.tableView endUpdates];
本·戈特利布

使用[NSIndexPath indexPathForRow:inSection:]快速创建一个索引路径。

编辑:在Swift 3:

let indexPath = IndexPath(row: rowIndex, section: sectionIndex)

迅捷5

IndexPath(row: 0, section: 0)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章