I want to create a view like, iOS
contact app has,
Basically i want is, Vertical
ABCDEFG....
which is located on right side of this image, when user clicks on characterM
i want to get characterM
How should i achieve this ? is there any iOS control which gives me this `ABCDEF...?
Thanks in advnace.
EDIT
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [[NSArray arrayWithObject:UITableViewIndexSearch] arrayByAddingObjectsFromArray:
[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if (title == UITableViewIndexSearch)
{
CGRect searchBarFrame = self.searchDisplayController.searchBar.frame;
[tableView scrollRectToVisible:searchBarFrame animated:YES];
return -1;
}
else {
UILocalizedIndexedCollation *currentCollation = [UILocalizedIndexedCollation currentCollation];
NSLog(@"selected charecter=%ld",(long)[currentCollation sectionForSectionIndexTitleAtIndex:index]);
return [currentCollation sectionForSectionIndexTitleAtIndex:index-1];
}
}
You need to implement these two methods:
// return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
// tell table which section corresponds to section title/index (e.g. "B",1))
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
with the corresponding data source:
For example, if you have an array with
`@"Cat", @"Mouse", @"Dog", @"Horse", @"Duck", @"Monkey"`
then you would return and array for sectionIndexTitlesForTableView
as :
`@[@"C", @"D", @"H", @"M"]`
because @"Dog"
and @"Duck"
goes for @"D"
, @"Mouse"
and @"Monkey"
goes for @"M"
and so on.
And of course, for sectionForSectionIndexTitle
, you return the corresponding index for that index. (1 for @"D"
, 3 for @"M"
etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With