[英]UITableView Index scrolling issue
我正在嘗試索引表並在單擊索引條目時滾動到正確的行。 該表在每行中有一個字母A..Z。 該指數也有A..Z。 向下滾動時可以正常工作。 例如,當我點擊索引中的“H”時,表格會滾動,以便H是第一行,但現在當我點擊“A”時,屏幕上有一半的空白區域,然后一行顯示在中間。 這是為什么? 由於我是新會員,我無法發布圖片。
我只有一節。 我為部分計數返回1,為部分行計數返回26。
我在方法sectionForSectionIndexTitle中的代碼是
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSLog(@"getting called %d",index);
int position;
switch (index) {
case 0:
position=0;
break;
case 1:
position=1;
break;
case 2:
position=2;
break;
case 3:
position=3;
break;
case 4:
position=4;
break;
case 5:
position=5;
break;
case 6:
position=6;
break;
case 7:
position=7;
break;
case 8:
position=8;
break;
case 9:
position=9;
break;
case 10:
position=10;
break;
case 11:
position=11;
break;
case 12:
position=12;
break;
case 13:
position=13;
break;
case 14:
position=14;
break;
case 15:
position=15;
break;
case 16:
position=16;
break;
case 17:
position=17;
break;
case 18:
position=18;
break;
case 19:
position=19;
break;
case 20:
position=20;
break;
case 21:
position=21;
break;
case 22:
position=22;
break;
case 23:
position=23;
break;
case 24:
position=24;
break;
case 25:
position=25;
break;
case 26:
position=26;
break;
default:
position=1;
break;
}
NSLog(@"scrolling to %d",position);
[tableView reloadInputViews];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:position inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
return index;
}
嘗試這件事.....我這是工作..
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:position inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
K來自問題的內容
UITableView
數據源和委托 Indexpath有兩個參數行和部分
NSIndexPath *index=[NSIndexPath indexPathForRow:position inSection:section]
[tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];
在didSelectRowAtIndexpath方法中,您將擁有indexpath並在單擊時滾動,因此
[tableView scrollToRowAtIndexPath:indexpath atScrollPosition:UITableViewScrollPositionTop animated:YES];
將足以實現這一目標
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.