views:

113

answers:

1

I have a UITableView that is populated with cells of a variable height. I would like the table to scroll to the bottom when the view is pushed into view.

I currently have the following function

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[log count]-1 inSection:0];
[self.table scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

log is a mutable array containing the objects that make up the content of each cell.

The above code works fine in viewDidAppear however this has the unfortunate side effect of displaying the top of the table when the view first appears and then jumping to the bottom. I would prefer it if the table view could be scrolled to the bottom before it appears.

I tried the scroll in viewWillAppear and viewDidLoad but in both cases the data has not been loaded into the table yet and both throw an exception.

Any guidance would be much appreciated, even if it's just a case of telling me what I have is all that is possible.

+3  A: 

I believe that calling [ table setContentOffset: CGPointMake(...) ] will do what you want.

Jacob Relkin
That's perfect thank you. I created a CGPoint with a sufficiently high Y value that will make it always display the bottom.Once the view has loaded I can use (self.table.contentSize.height - self.table.frame.size.height) to move to the bottom with the same method
acqu13sce
Awesome. Glad i could help out.
Jacob Relkin
Also, upvote please? ;)
Jacob Relkin