我想更新的UITableView時將滾動到頂部。在facebook應用中,當我們將uitableview滾動到頂部時,它會顯示「upadating」並在表格視圖頂部插入新行。我想在我的應用程序中發揮同樣的效果。有可能使用默認的uitableview方法來設計它,或者我們需要定製它。 如果有人有想法請回復。的UITableView autoupadate而滾動到頂部
回答
您可以使用insertRowsAtIndexPaths:
在表格視圖的前面插入新行。例如,
NSIndexPath *indexPathForRow_0_0 = [NSIndexPath indexPathForRow:0 inSection:0];
NSIndexPath *indexPathForRow_0_1 = [NSIndexPath indexPathForRow:1 inSection:0];
[yourTableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathForRow_0_0, indexPathForRow_0_1, nil] withRowAnimation:UITableViewRowAnimationTop];
上面的代碼中插入該指數在0和1兩個排在第0
注:您需要定製dataSource
和delegate
方法與這些插入調整。重要的是你需要從numberOfRowsInSection
方法返回正確的值。這裏,在上面的例子中,你numberOfRowsInSection
方法應返回yourPreviousNumberOfRows + 2,因爲我們在這裏添加了兩個行。
您可能希望當用戶滾動到頂部檢測:
幾種方法可以做到這一點:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y == 0)
NSLog(@"At the top");
}
來源:How can I get scrollViewDidScrollToTop to work in a UITableView?
或者使用:
scrollViewDidScrollToTop:
您現在可以解僱你的事件,這取決於用戶的操作: 即 當用戶滾動到頂部,使用打電話給你的用戶界面的變化,然後調用您的更新邏輯。
insertRowsAtIndexPaths:withRowAnimation:
樣品和資料來源:更新邏輯已經結束http://www.mlsite.net/blog/?p=466
後,調用[的tableView reloadData]假設你的數據源現在已更新。或者,您可能希望使用deleteRowsAtIndexPaths:withRowAnimation:在刪除您的單元格時通知您當前正在更新時添加效果。
滾動視圖可以有插圖的內容(例如,觀點背後的導航欄,而從導航欄的末尾內容開始)。 scrollView.contentOffset.y + scrollView.contentInset.top == 0應該會更好。 – Kazuki 2014-06-16 01:36:15
另一種方式:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0) {
[self fetchMoreMessages];
}
}
- 1. 自動滾動到頂部在UITableView
- 2. iPad UITableView滾動彈回回到頂部
- 3. 獲取UITableView從底部/捕捉到底部滾動,而不是頂部
- 4. Windows滾動工作滾動到頂部而不是底部
- 5. UITableView - 保持最底部的單元格滾動到頂部?
- 6. 雙擊UITabBarItem不會滾動UITableView頂部
- 7. 的jQuery#滾動到頂部
- 8. uitableview不滾動到底部
- 9. 停止iPhone的UITableView從滾動到頂部
- 10. Android ListView滾動到頂部
- 11. 滾動到燈箱頂部
- 12. BlockUI滾動到頂部
- 13. CollectionView滾動到頂部
- 14. 禁用滾動到頂部
- 15. 網格:滾動到頂部?
- 16. 滾動到頂部DIV
- 17. UIScrollView不滾動到頂部
- 18. LinearLayout滾動到頂部
- 19. 滾動到頂部代碼
- 20. 當插入更多行時,UITableView滾動到頂部
- 21. 滾動最後一個單元格到UITableView頂部
- 22. Swift 2.0 UITableView Section Header點擊滾動到頂部
- 23. 當重新加載UITableView使它不滾動到頂部
- 24. UITableView在tableView標題中用SearchController滾動到頂部
- 25. UITableview滾動到頂部上重載過高?
- 26. jquery滾動到頂部的動畫
- 27. iOS UITableView滾動到部分底部
- 28. 當滾動到頂部而不是底部時添加元素
- 29. Clicked Header Section滾動到頂部
- 30. 頂部的UITableView
謝謝..你有任何教程鏈接呢? – Gaurav 2011-02-01 06:13:52
對不起的人。我沒有任何聯繫的教程..我想簡單的谷歌搜索將幫助你.. – EmptyStack 2011-02-01 08:42:30