4

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.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
Fittoburst
  • 2,215
  • 2
  • 21
  • 33

1 Answers1

9

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.
}
rintaro
  • 51,423
  • 14
  • 131
  • 139
  • #rintaro. Thanks...works perfectly. So my next question is...why? – Fittoburst Dec 08 '14 at 13:36
  • What would be the ideal place to put this in. Would it be here ... func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { .... OR in viewDidAppear() etc – ioopl Jun 19 '16 at 00:27