【问题标题】:iOS/Swift - UITableView reloadData not being callediOS/Swift - UITableView reloadData 没有被调用
【发布时间】:2017-02-11 03:39:27
【问题描述】:

我的表视图控制器类有以下方法:

func reloadInputFields() {
    dispatch_async(dispatch_get_main_queue()) {
        self.tableView.beginUpdates()
        self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Automatic)
        self.tableView.endUpdates()
    }
}

这是从 NSNotification 调用的。运行时很好地进入了这个方法,并且似乎调用了 reloadSections。然而,它从来没有真正做到过。显然我在这里的主线程上执行,因为它是一个 UI 更新,但我也尝试过在后台线程上。我也试过只打电话给tableView.reloadData()而不是reloadSections,但那里没有快乐。表格视图肯定存在,我检查过指针是否正确。

cellForRowAtIndexPathnumberOfSectionsInTableViewheightForRowAtIndexPathnumberOfRowsInSection 等中的断点未命中且表未重新加载。

我的delegatedataSource 设置正确,此处已验证:

我已经为此苦苦挣扎了几个小时,完全胜过我。如有任何建议,我们将不胜感激。

【问题讨论】:

  • 是被称为部分的行数吗?
  • 不,不是迈克,应该也列出那个。
  • 先检查delegate,如果你是拖放表格,则无需分配tableview尝试一次。
  • 请尽可能多地展示您的代码。
  • 为什么这个问题被否决并投票结束?

标签: ios swift uitableview nsnotificationcenter reloaddata


【解决方案1】:

解决此问题的一些建议:

1. Make sure you have IBOutlet connection to the UITableView.

2. Check delegate and datasource. If necessary, write them programmatically.

3. Make sure your tableView is populated with data before triggering notification.

4. Avoid beginUpdates and endUpdates and use only reloadData on main thread.

【讨论】:

    【解决方案2】:

    触发通知时表格视图是否处于活动状态? 检查表视图控制器是否被释放(它是不活动的。可能没有显示在屏幕上)

    【讨论】:

    • 感谢您的建议,但通知是从表格视图的其中一个单元格中的文本字段发送的,这意味着表格视图在屏幕上。
    • 检查您的问题是否与此类似:stackoverflow.com/questions/26758101/…
    猜你喜欢
    • 1970-01-01
    • 2016-04-05
    • 2015-05-17
    • 2011-09-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多