Ios 单NSArray的UITableView索引实现

Ios 单NSArray的UITableView索引实现,ios,uitableview,ios7,Ios,Uitableview,Ios7,大家好,我正在尝试使用UITableView索引的一个。我已经使用两个数组完成了所有相关的实现,第一个数组用于字符串数据,第二个数组是字母表索引。我可以在表视图的右侧看到索引,但当我单击它时,表视图会滚动到顶部。这是我的UITableview方法代码 - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {

大家好,我正在尝试使用UITableView索引的一个。我已经使用两个数组完成了所有相关的实现,第一个数组用于字符串数据,第二个数组是字母表索引。我可以在表视图的右侧看到索引,但当我单击它时,表视图会滚动到顶部。这是我的UITableview方法代码

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title  atIndex:(NSInteger)index
{
    NSLog(@"index = %d, title = %@",index,title);


        NSUInteger row = 0;
        for(NSString *accountInfo in sortedDataArrayList)
        {
            NSLog(@"[accountInfo substringFromIndex:1] = %@",[accountInfo.accountName substringToIndex:1]);
            if([accountInfo length]>0 && [[accountInfo substringToIndex:1] caseInsensitiveCompare:title] == NSOrderedSame)
            {

                NSLog(@"row = %d",row);
                [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
                break;
            }
            row++;
        }
    }
    return 0;
}

- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView
{
    if(currentFilterMode == FilterModeAll )
    {

        return self.indexArray;

    }
    return nil;

}

任何人请告诉我我哪里做错了。单击索引按钮后,tableview仅滚动到顶部,而不是按照索引位置滚动。

从您的代码中,我可以理解的是您对该概念有一点误解。为了使输出如您所期望的那样,它需要分区的tableview

你可以在这里读到一篇很好的博客文章

在代码中,您将移动到第0节的行

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
我认为您需要将索引节编号改为0。请您尝试设置需要移动的部分


希望这能解决你的问题。。谢谢。

谢谢你的回复。我很清楚,在实现它自己的时候,也有一个单一部分的可能性。