我正在尝试制作一个带有索引的字母表,当我单击前 14 个字母时,它会显示正确的字母,但之后它会不断重复并只显示第 14 个字母。请帮助..这是我的代码:(字母不是英文:))
- (void)viewDidLoad
{
[super viewDidLoad];
_arr=[NSArray arrayWithObjects:@"א",@"ב",@"ג",@"ד",@"ה",@"ו",@"ז",@"ח",@"ט",@"י",@"כ",@"ל",@"מ",@"נ",@"ס",@"ע",@"פ",@"צ",@"ק",@"ר",@"ש",@"ת",nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_arr count];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return self.arr;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)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;
default:
position=1;
break;
}
NSLog(@"scrolling to %d",position);
[tableView reloadInputViews];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:position inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
return index;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [self.arr objectAtIndex:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.font = [UIFont boldSystemFontOfSize:32];
cell.textLabel.text=[_arr objectAtIndex:indexPath.row];
return cell;
}