【发布时间】:2018-01-05 08:51:46
【问题描述】:
我有 N 个部分的 Tableview,其中修复了 0,1 个部分。永远不会从 tableview 中删除。但从第2节开始到N个节,可以删除或插入。从第 2 部分到 N 部分 -> 每个部分也有行数。
我在第 2 部分有 N 个部分的搜索功能。
这是整个代码
1。这是包含每个部分的行数的计数 dic ["section" : "no of rows"]
self.countDic.updateValue(1, forKey: "0")
self.countDic.updateValue(0, forKey: "1")
for i in 0..<arra1.count {
self.countDic.updateValue(array.count, forKey: "\(i + 2)")//[index : arraylist.count]
}
2.这是返回部分和行的 Tableview 方法
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return countDic["\(section)"]!
}
func numberOfSections(in tableView: UITableView) -> Int {
return countDic.count
}
3.这是搜索和表格重新加载代码
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let newString = NSString(string: textField.text!).replacingCharacters(in: range, with: string)
if (newString.isEmpty) {
FilterStr = ""
} else {
FilterStr = newString
}
let namesBeginningWithLetterPredicate = NSPredicate(format: "(title1 CONTAINS[cd] $letter)")
let arr : [Today_ActivityModel] = (Today_Activity_Data as NSArray).filtered(using: namesBeginningWithLetterPredicate.withSubstitutionVariables(["letter": FilterStr])) as! [Today_ActivityModel]
if FilterStr == "" {
self.countDic.removeAll()
FilterData.removeAll()
//self.GetRecordsCityWiseFilter(ArrayList: self.Today_Activity_Data)
} else {
if arr.count >= 0 {
FilterData.removeAll()
//self.GetRecordsCityWiseFilter(ArrayList: arr )
} else {
self.countDic.removeAll()
FilterData.removeAll()
//self.GetRecordsCityWiseFilter(ArrayList: self.Today_Activity_Data)
}
}
DispatchQueue.main.async {
UIView.performWithoutAnimation {
let indexSet = IndexSet(integersIn: 2..<self.TblView.numberOfSections)
self.TblView.reloadSections(indexSet, with: .bottom)
}
}
return true
}
在重新加载表格时,我尝试插入第 3 节,但更新后只有 3 个节
谁能帮我解决这个问题?
【问题讨论】:
-
为什么不使用两个不同的数组来处理所有这些事情,一个用于前 2 部分,第二个用于其他部分
-
我将为顶部和最后部分采用两个不同的数组。但最后我必须将表从第 2 部分重新加载到 n 个部分。这是主要的。
标签: ios swift uitableview reloaddata