3 回答

TA貢獻1817條經驗 獲得超14個贊
我解決此問題的方法是contentOffset根據(extends )contentInset中的來調整,如下所示:UITableViewControllerDelegateUIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
唯一的問題是,滾動回頂部時,它會松動一些反彈。
{注意:“ 40”應為您的第0部分標題的確切高度。如果使用的數字大于第0部分標題的高度,您會發現手指感覺受到了影響(嘗試使用“ 1000”,并且您會看到頂部的彈跳行為很奇怪)。如果數字與您的第0部分標題高度匹配,則手指感覺似乎是完美的或接近完美。}

TA貢獻1921條經驗 獲得超9個贊
如果是我這樣做,我將利用一個事實,即Plain風格的UITableViews具有粘性標頭,而Grouped風格的UITableViews沒有標頭。我可能至少會嘗試使用自定義表格單元格來模擬分組表格中普通單元格的外觀。
我實際上沒有嘗試過,因此可能無法正常工作,但這就是我建議的做法。

TA貢獻1875條經驗 獲得超5個贊
我知道來晚了,但是我找到了最終的解決方案!
您要執行的操作是,如果有10個節,則讓dataSource返回20。節標題使用偶數,節內容使用奇數。像這樣的東西
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section%2 == 0) {
return 0;
}else {
return 5;
}
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section%2 == 0) {
return [NSString stringWithFormat:@"%i", section+1];
}else {
return nil;
}
}
- 3 回答
- 0 關注
- 493 瀏覽
添加回答
舉報