[英]Scroll UITableView to a particular section
我希望我的UITableView
滾動到特定部分,我如何實現這一點。 我已經嘗試了很多關於SO的建議,並且出於某些奇怪的原因,似乎沒有任何效果。 任何幫助表示贊賞。 謝謝。
請嘗試使用以下代碼行:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSInteger Section=3;//Change as required
NSInteger Row=0;//Change as required
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:Row inSection:Section];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
編輯:
使用以下NSIndexPath
滾動到包含0行的部分:
[NSIndexPath indexPathForRow:NSNotFound inSection:section]
滾動tableview,以便所需的部分可見,但不一定在頂部或底部:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
[tableView scrollRectToVisible:sectionRect animated:YES];
滾動以使該部分位於頂部,請執行以下操作:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
sectionRect.size.height = tableView.frame.size.height;
[tableView scrollRectToVisible:sectionRect animated:YES];
在此處檢查答案: 如何將UITableView滾動到不包含任何行的部分?
嘗試使用這個
[self.tableView scrollToRowAtIndexPath:YOUR_INDEX_PATH_OF_SECTION atScrollPosition:UITableViewScrollPositionTop animated:YES]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.