Ios InsertSections函数
我的目标是在单击后插入一个部分,并在此部分中插入4行 我已经熟悉了如何使用InsertRowsAtIndexPaths,在一个节中插入行并没有问题。Ios InsertSections函数,ios,swift,uitableview,sections,Ios,Swift,Uitableview,Sections,我的目标是在单击后插入一个部分,并在此部分中插入4行 我已经熟悉了如何使用InsertRowsAtIndexPaths,在一个节中插入行并没有问题。但在插入新节时,这很棘手,苹果的文档也没有充分解释 下面是我用来插入行的代码 self.tableView!.beginUpdates() var insertedIndexPaths: NSMutableArray = [] for var i = 0; i < newObjects.count + 1; ++i { insertedInde
但在插入新节时,这很棘手,苹果的文档也没有充分解释 下面是我用来插入行的代码
self.tableView!.beginUpdates()
var insertedIndexPaths: NSMutableArray = []
for var i = 0; i < newObjects.count + 1; ++i {
insertedIndexPaths.addObject(NSIndexPath(forRow: initialCount + i, inSection: sectionsnumbers)) }
self.tableView?.insertRowsAtIndexPaths(insertedIndexPaths as [AnyObject], withRowAnimation: .Fade)
self.tableView!.endUpdates()
self.tableView!。开始更新()
var insertedIndexPaths:NSMutableArray=[]
对于var i=0;i
任何例子,见解都是非常感谢的
谢谢。插入节时,其数据将重新加载。您不需要单独告诉tableview关于所有新行的信息;它只会询问数据源新部分中的行数
有关更多信息,请参见。使用
var sectionNumbers:NSMutableArray=({“object”:“object”})//等您想要的任何对象
现在使用这个函数
func numberOfSectionsInTableView(tableView: UITableView) -> Int{
返回sectionNumbers.count}
在SectionNumber中添加对象,并在要添加section的位置调用此方法
tableView.reloadData()
这将有助于插入节与插入行不同。如果要插入行,需要先调用tableView.BeginUpdate(),然后调用table.endUpdates(),否则会引发一些数据不一致异常。另一方面,在插入节时,您不必做任何事情,只需反映数据源中的更改,如NumberOfSectionsTableView。这种方法有几个问题。基本委托和数据源方法已经实现。至于tableView.reloadData()-它不允许我保留所需的动画,这就是为什么我试图实现insertSection func。