Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift and reloadRowsAtIndexPaths compilation error

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.

like image 630
Fittoburst Avatar asked Jan 10 '23 07:01

Fittoburst


1 Answers

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.
}
like image 107
rintaro Avatar answered Jan 11 '23 19:01

rintaro