0

I have an NSTableView inside and NSScrollView in a pretty standard configuration. When I sort the table view (by clicking one of the column headers), everything that is currently visible gets displayed correctly, but when I scroll in any direction (left, right, up, down) the cells that I scroll to haven't been updated correctly. If half a cell was visible when I sorted, it will even display half the cell with the old value and half the cell with the new value when I scroll to view the whole cell.

Whats going on? Can I force the table view to redraw everything when I sort the table?

Drew
  • 12,578
  • 11
  • 58
  • 98

1 Answers1

0

When you need to redraw table just call:

[yourTableViewOutlet reloadData];

Reference here.

reloadData

Marks the table view as needing redisplay, so it will reload the data for visible cells and draw the new values.

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
  • How do I know when I need to redraw the table though? Is there a callback for when the table is sorted? Or maybe when its scrolled? (although I can imagine that being a big performance hit, redrawing with every scroll) – Drew Dec 18 '12 at 22:37
  • @Drew take a look at this apple's example. It should help you http://developer.apple.com/library/mac/#samplecode/NSTableViewBinding/Introduction/Intro.html. And one more question: maybe you are using Core Animation Layers? This can cause this problem. – Justin Boo Dec 18 '12 at 23:00
  • When you click the header, in the last line just before `}` call `[_tableView reloadData];` – Anoop Vaidya Dec 19 '12 at 07:25