【发布时间】:2014-12-25 04:16:13
【问题描述】:
我想用动画展开/折叠我的UITableView 部分。我使用了this 的答案,如果我打电话给self.tableView.reloadData(),它现在可以工作了。但是我希望当我点击我的自定义 UITableView- 标题时,该部分的单元格应该向下/向上滑动并带有漂亮的动画。我尝试使用self.tableView.beginUpdates() 和self.tableView.endUpdates(),但出现此错误:
Invalid update: invalid number of rows in section 0. The number of rows contained in an
existing section after the update (8) must be equal to the number of rows contained in that
section before the update (0), plus or minus the number of rows inserted or deleted from
that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out
of that section (0 moved in, 0 moved out).
这里有一些代码。点击该部分时调用的方法:
func expand(sender:UITapGestureRecognizer){
let tag = (sender.view?.tag)!
self.tableView.beginUpdates()
if ausgeklappt[tag] { ausgeklappt[tag] = false }
else { ausgeklappt[tag] = true }
self.tableView.endUpdates()
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
let keyDerSection = sortSpieleDict.keys.array[section]
let arrayDerSection = sortSpieleDict[keyDerSection]!
if ausgeklappt[section] == false { return 0 }
else { return arrayDerSection.count }
}
谢谢。
【问题讨论】:
-
嘿!查看此链接:stackoverflow.com/questions/1938921/… 这个很旧,但可能会对您有所帮助。
-
我用这个答案来设置一切。但答案不使用动画。我还将答案链接到我的问题中。
-
抱歉,我没有看到您问题中的链接。我将在一段时间内发布我在我的一个项目中使用的代码。它使用动画展开/折叠。
标签: ios iphone uitableview animation swift