views:

386

answers:

2

Hi,

I'm dynamically adding rows to an NSTableView. When I issue [table reloadData] I can see the scroll view move and if I move it by hand I can see the new value on the table. But how can I scroll it automatically?

+5  A: 

Use something like this:

 [table scrollRowToVisible:indexOfNewRow];
Frank Schmitt
+1 because this way handles the usual case where table sorting means that the new row isn't necessarily at the bottom of the table.
Abizern
+6  A: 
NSInteger numberOfRows = [tableView numberOfRows];

if (numberOfRows > 0)
    [tableView scrollRowToVisible:numberOfRows - 1];

Assuming you're adding rows to the end of the table.

(The reason I ask the table view for the number of rows instead of the data source is that this number is guaranteed to be the number of rows it knows about and can scroll to.)

Wevah