我需要在我定义的函数中删除表的第 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)
indexPathForRow
是一个类方法!
代码应为:
NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0] ;
Swift 中的强制性答案:NSIndexPath(forRow:row, inSection: section)
您会注意到 NSIndexPath.indexPathForRow(row, inSection: section)
在 swift 中不可用,您必须使用第一种方法来构造 indexPath。
对于 Swift 3,它现在是:IndexPath(row: rowIndex, section: sectionIndex)
不定期副业成功案例分享