ios - InsertSections 函数 Swift

标签 ios swift uitableview sections

我的目标是通过点击插入一个部分,并向该部分插入 4 行。

我已经熟悉如何使用 InsertRowsAtIndexPaths 并且将行插入一个部分没有问题。

但是当涉及到插入新部分时,它很棘手并且苹果文档没有完整解释。

这是我用来插入行的代码

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()

非常感谢任何示例和见解。

谢谢。

最佳答案

当您插入一个部分时,它的数据会重新加载。您不需要单独告诉 TableView 所有新行;它只会向数据源询问新部分中的行数。

参见 this document获取更多信息。

关于ios - InsertSections 函数 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32349866/

相关文章:

ios - 当我播放嵌入的YouTube视频时,如何将我的iOS应用名称作为流量来源传递?

ios - uitableview contentInset 问题

iOS 9 UIAlertView 现在已弃用并被 UIAlertController 取代,如何在 UIView 上显示它,因为 View 没有方法 presentViewController

ios - 如何检索 autoId 以删除值

ios - alamofire 在 swift 3 中上传相机和图库图像

ios - 使用missViewControllerAnimated隐藏键盘

swift - 硬件音量按钮和 Swift

iOS 8 TableView Controller 性能问题

ios - JSON 的 Swift 编码/解码图像

ios - 无法从 UITextField 读取 XCode 8 中的数字