-
Add Section Index Title search in one section of UITableVIew in iPhone
almost 11 years ago
almost 11 years ago
Add Title search on UItableVIew
- - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
- return [NSArray arrayWithObjects:@"A", @"B", @"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X", @"Y", @"Z", nil];
}
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
- {
- for (int i = 0; i< [allnames count]; i++) {
- // Here you return the name i.e. Honda,Mazda
- // and match the title for first letter of name
- // and move to that row corresponding to that indexpath as below
- NSString *letterString = [[allnames objectAtIndex:i] substringToIndex:1];
- if ([letterString isEqualToString:title]) {
- [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
- break;
- }
- }
- }
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return [NSArray arrayWithObjects:@"A", @"B", @"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X", @"Y", @"Z", nil];} - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { for (int i = 0; i< [allnames count]; i++) { // Here you return the name i.e. Honda,Mazda // and match the title for first letter of name // and move to that row corresponding to that indexpath as below NSString *letterString = [[allnames objectAtIndex:i] substringToIndex:1]; if ([letterString isEqualToString:title]) { [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES]; break; } } }
0 Comment(s)