特定部分应位于表格视图的顶部

Posted

技术标签:

【中文标题】特定部分应位于表格视图的顶部【英文标题】:particular section should go to the top of the tableview 【发布时间】:2013-09-27 09:25:03 【问题描述】:

我有一个UITableview,在其中我使用viewForHeaderInSection 方法像下拉菜单一样自定义视图,因此当我选择节标题视图上的特定按钮时,行的单元格看起来像下拉菜单。我需要一种方法,这样当我选择特定部分时,该部分应该转到表格视图的顶部。

有解决方案来实现吗?

【问题讨论】:

很好的问题,但你必须尝试什么???关注developer.apple.com/library/ios/samplecode/TableViewUpdates/… 这可能会有所帮助***.com/questions/8441922/… 另请阅读***.com/questions/5353680/… 【参考方案1】:

首先根据下拉选择获取部分。

CGRect rect = [tableView rectForHeaderInSection:(NSInteger)section];

[tableView setContentOffset:CGPointMake(0.0, rect.origin.y)
             animated:YES];  

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]                                                
               atScrollPosition:UITableViewScrollPositionTop
                       animated:YES];

【讨论】:

以上是关于特定部分应位于表格视图的顶部的主要内容,如果未能解决你的问题,请参考以下文章