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 部分”**
谁能建议怎么做?
这是斯威夫特。
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)
| 归档时间: |
|
| 查看次数: |
2180 次 |
| 最近记录: |