Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make NSTableView scroll to most recently added row?

Tags:

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?

like image 540
ruipacheco Avatar asked Nov 25 '09 20:11

ruipacheco


2 Answers

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.)

like image 108
Wevah Avatar answered Nov 16 '22 10:11

Wevah


Use something like this:

 [table scrollRowToVisible:indexOfNewRow]; 
like image 26
Frank Schmitt Avatar answered Nov 16 '22 10:11

Frank Schmitt