开发者

No scrolling occurs when UITableView scrollToRowAtIndexPath is invoked

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 UITableV开发者_JAVA百科iewController


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜