views:

48

answers:

1

My view contains a simple TableView with 6 rows and a button that invokes doScroll when clicked. My objective for doScroll() is simply scroll to the 5th cell such that it's at top of the table view.

- (void)doScroll: (id)sender
{
    NSIndexPath *index = [NSIndexPath indexPathForRow:4 inSection: 1];
    [m_tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

However when doScroll is invoked, the tableview scrolls only slightly. I suspect this has something to do with the size of the scroll view. So I tried increasing the height of m_tableview.contentsize before scrolling. After I do this however, no scrolling occurs at all...

The view controller is a simple UIViewController and refers to the table view via IBOutlet. For some reason, scrolling works as expected for the default Navigation Based Application, where the controller is a UITableViewController

+2  A: 

The UITableView will prevent you from scrolling up empty space. Add enough valid content to the bottom of the table so the cell can scroll up. Use the bounds of the table less the height of the cell for a more accurate frame:

myTable.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)] autorelease];

You could also just use the bottom of the contentInset property.

drawnonward