//设置索引
- (NSArray *)sectionIndexTitlesForTableView:(UITableView*)tableView
{
if (tableView == myTableView) {
NSMutableArray *charArray = [[NSMutableArray alloc]initWithCapacity:0];
//加一个搜索索引
[charArray addObject:UITableViewIndexSearch];
[charArray addObject:@"中国"];
[charArray addObject:@"外国"];
return charArray;
}
return nil;
}
//解决加入索引图标混乱
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if (index == 0) {
[tableView scrollRectToVisible:tableView.tableHeaderView.frameanimated:YES];
}
//返回的是section
return index-1;
}