iOS Swift and reloadRowsAtIndexPaths compilation error

自古美人都是妖i 提交于 2019-12-21 05:15:55

问题


I've hit deadlock with xCode/Swift and refreshing a single row of UITableView.

This line works....

self.tableView.reloadData();

whereas this line doesn't

self.tableView.reloadRowsAtIndexPaths([_currentIndexPath], withRowAnimation: UITableViewRowAnimation.None);

Auto-complete is suggesting reloadRowsAtIndexPaths and giving the syntax but on compilation, I'm getting the error:

'Could not find member 'reloadRowsAtIndexPaths'.

If I right click and 'jump to definition' in self.tableview, the symbol is not found.

I'm hoping I'm not doing anything embarrassingly stupid here and would appreciate help. I could use reloadData but want to know why this isn't working here.


回答1:


I believe, _currentIndexPath is Optional. something like

var _currentIndexPath:NSIndexPath?

So try:

if let indexPath = _currentIndexPath {
    self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
}
else {
    // `_currentIndexPath` is nil.
    // Error handling if needed.
}


来源:https://stackoverflow.com/questions/27357178/ios-swift-and-reloadrowsatindexpaths-compilation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!