In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section number 5.
So I get an exception, when I call:
```[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
```
Is there another way to scroll to the top of table view?
Yes, there is an alternative way to scroll to the top of the table view, that doesn't depend on the position of the first object. You can simply set the table view's content offset to the top position using the following code:
```objective
[mainTableView setContentOffset:CGPointMake(0, mainTableView.contentInset.top) animated:NO];
```
This code sets the table view's content offset
You're right that if the first object isn't in the first section, then attempting to scroll to section 0, row 0 will result in an exception. However, scrolling to the top of the table view isn't necessarily limited to that specific index path. Instead, you can scroll to the top of the content, regardless of where the first object is located, by invoking the `scrollToTop` method of `UITableView`: