ios - 一次插入两个部分

标签 ios objective-c uitableview

这里,我尝试在 Section 2 中填写地址后立即插入 Sections 1Section 3。最初它们必须隐藏或仍然不插入表​​ View 中。我成功插入了 Section 3,但无法插入 Section 2。这是我在第 2 部分 中填写地址后的代码。

-(void)viewWillAppear:(BOOL)animated {

  [self.reviewOrderList insertSections:[NSIndexSet indexSetWithIndex:3] 
  withRowAnimation:UITableViewRowAnimationBottom];
  [self.reviewOrderList reloadData];

 }

enter image description here

最佳答案

您可以创建 NSMutableIndexSet 的实例并添加要添加的部分的索引。然后你可以在-[UITableView insertSections:withRowAnimation:]中传递该indexSet 。您不需要调用-[UITableView reloadData]之后:插入方法会自动执行显示新部分所需的操作。您甚至可以通过调用 -[UITableView beginUpdates] 批量进行多个更改并立即为它们设置动画。在进行更改并通过调用 -[UITableView endUpdates] 完成更改之前.

有关更多信息,请查看 UITableView Class Reference .

关于ios - 一次插入两个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143988/

相关文章:

ios - 单击 UIButton 时 UITableView 卡住

ios - 使用 Swift 隐藏取消隐藏静态 TableView 单元格

iOS10 小部件 "Show more" "Show less"错误

objective-c - 检测删除键被按下

ios - 苹果使用哪种字体/字体大小作为 iOS 中的占位符

objective-c - 转义 NSDateFormatter 字符串

iOS:EXC_BAD_ACCESS 错误 NSString 长度和 setHTTPBody

swift - 自定义 UITableView 内的 UITextField 在 Swift 中为零

iphone - 将 JSON 数据写入磁盘

ios - CocoaPods 测试版