重新加载tableView部分而不重新加载标题部分 - Swift [英] Reload tableView section without reloading header section - Swift

查看:135
本文介绍了重新加载tableView部分而不重新加载标题部分 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新加载tableView部分而不是重新加载整个tableview,因为我在标题部分有一个文本字段,当我调用 self.tableView.reloadData()我的键盘关闭了。

I'm trying to reload tableView section instead of reloading the whole tableview because I have a textfield in the header section and when I call self.tableView.reloadData() my keyboard get closed.

我已经尝试了下面的代码,但是我收到此错误由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'尝试删除行第2节中的5,在更新'之前只包含4行所以请问我的问题在哪里?

I've tried the code below but I get this error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 5 from section 2 which only contains 4 rows before the update' So please where would be my issue?

    let newCount = self.placeArray.count

    var newIndexPaths = NSMutableArray(capacity: newCount)

    for var i = 0 ; i < newCount ; i++ {
    var indexPath = NSIndexPath(forRow: i, inSection: 2)
        newIndexPaths.addObject(indexPath)
    }

    self.tableView.beginUpdates()
    self.tableView.reloadRowsAtIndexPaths(newIndexPaths as [AnyObject], withRowAnimation: UITableViewRowAnimation.None)
    self.tableView.endUpdates()


推荐答案

您可以使用 UITableView reloadSections 方法。

tableView.reloadSections(NSIndexSet(index: 2), withRowAnimation: .None)

这篇关于重新加载tableView部分而不重新加载标题部分 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆