重新加载除第一和第二部分之外的所有部分

Vis*_*l N 1 tableview ios swift

我有包含多个部分的 Tablview。

第一部分 -它包含搜索文本框
第二部分 -它包含 UIView
其他部分 - 这部分我想在搜索时重新加载。

更新
我设置了 countdic 和 tableview,如下所示:-
1. 设置 countdic

self.countDic.updateValue(1, forKey: "0")// this is for First section
self.countDic.updateValue(0, forKey: "1")//this is for second section
for i in 0..<arra1.count {
    self.countDic.updateValue(array.count, forKey: "\(i + 2)")//[index : arraylist.count]
}
Run Code Online (Sandbox Code Playgroud)


2.这是我的tableview设置

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return countDic["\(section)"]!
 }

func numberOfSections(in tableView: UITableView) -> Int {
    return countDic.count
}
Run Code Online (Sandbox Code Playgroud)


3. 我在这里重新加载 tableview
这是来自UITextfield的 shouldChangeCharactersIn

 let indexSet = IndexSet(integersIn: 2..<self.TblView.numberOfSections)
 self.TblView.reloadSections(indexSet, with: .bottom)
Run Code Online (Sandbox Code Playgroud)

但它使应用程序崩溃并出现错误:

** 原因:“尝试插入第 3 部分,但更新后只有 3 部分”**

谁能建议怎么做?

vad*_*ian 5

这是斯威夫特。

  • NS(Make)Range不合适
    (顺便说一下,第二个参数NSMakeRange长度不是结束索引
  • NSMutableIndexSet 不合适

使用 Swift 功能:

let indexSet = IndexSet(integersIn: 2..<self.countDic.count)
self.TblView.reloadSections(indexSet, with: .bottom)
Run Code Online (Sandbox Code Playgroud)