我有一个tableview,按照从最旧到最新的顺序列出了大约10个单元格。当我打开"编辑模式"并删除单元格,一切似乎都正常工作。
但我创建了一些函数,根据各种属性将这些单元格置于不同的顺序。当我在这些不同的排序顺序中使用编辑模式时,错误的单元格似乎被删除。
以下是我的某个排序函数的代码。
C:\FE-Proj-Templates\webpack>npm i -D redux
npm WARN package.json ozone@1.0.0 No description
npm WARN package.json ozone@1.0.0 No repository field.
npm WARN package.json ozone@1.0.0 No README data
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files (x86)\\Nodist\\v-x64\\4.5.0\\node.exe" "C:\\Program Files (x86)\\No
dist\\npmv\\2.15.9\\bin\\npm-cli.js" "i" "-D" "redux"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! code EPEERINVALID
npm ERR! peerinvalid The package webpack@2.1.0-beta.21 does not satisfy it siblings' peerDependenci
es requirements!
npm ERR! peerinvalid Peer babel-loader@6.2.5 wants webpack@1 || ^2.1.0-beta
npm ERR! peerinvalid Peer extract-text-webpack-plugin@1.0.1 wants webpack@^1.9.11
npm ERR! peerinvalid Peer sass-loader@4.0.0 wants webpack@^1.12.6 || ^2.1.0 beta
npm ERR! peerinvalid Peer webpack-dev-server@2.0.0-beta wants webpack@>=2.0.3-beta <3
npm ERR! peerinvalid Peer html-webpack-plugin@2.22.0 wants webpack@*
npm ERR! Please include the following file with any support request:
npm ERR! C:\FE-Proj-Templates\webpack\npm-debug.log
这是我删除功能的代码。
func sortPokemonListbyAveIV(){
self.pokemonList.sortUsingComparator{
(obj1: AnyObject, obj2: AnyObject) -> NSComparisonResult in
let first = obj1 as! NSDictionary
let second = obj2 as! NSDictionary
var firstIVRange = ""
var secondIVRange = ""
if((first["iv"] as! String).containsString("Sorry")){
firstIVRange = "IV: 1 - 2%"
} else {
firstIVRange = (first["iv"] as! String).stringByReplacingOccurrencesOfString("--", withString: "-")
}
if((second["iv"] as! String).containsString("Sorry")){
secondIVRange = "IV: 1 - 2%"
} else {
secondIVRange = (second["iv"] as! String).stringByReplacingOccurrencesOfString("--", withString: "-")
}
// let firstIVRange = first["iv"] as! String
// let secondIVRange = second["iv"] as! String
let firstAveIV = self.avgIV(firstIVRange)
// print(firstIVRange)
let secondAveIV = self.avgIV(secondIVRange)
let result = firstAveIV - secondAveIV
return (result < 0) ? .OrderedDescending
: (result == 0) ? .OrderedSame : .OrderedAscending
}
}
我怀疑我需要编辑删除功能代码以考虑tableview中当前的活动排序顺序。我不太确定如何做到这一点。
答案 0 :(得分:1)
您不需要在tableView.reloadData()
之后致电tableView.deleteRowsAtIndexPaths
。由于调用reloadData
将触发整组tableView委托和数据源方法,如cellForRowAtIndexPath
,numberOfRowsInSection
等。