The index is used to assist in the enquiry.
Principle:
-The title of the index is not exactly the same as the title display;
-The index should have a certain representation, it can represent a set of data;
-Assume an indexed list view. The extended view is no longer used in general.
(Easy pointing)
It's going to be another time. Data source methods:
Tableview:numberofrowsinsection:------Gets the number of rows in a section
Tableview:cellforrowatindexpath: Implementation of-------cell data
Numberofsectionintableview:----------Get the number of sections
Tableview:titleforheaderinsection:--------section title
Sectionindextitlesfortableview:--------Get Index
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbgl5ywt1bje5ota=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; NSBundle *bundle = [NSBundle mainbundle]; NSString *plistpath = [Bundle pathforresource:@ "Team_dictionary" oftype:@ "plist" ]; Get all the data in the attribute list file Self.dicdata = [[Nsdictionary alloc] initwithcontentsoffile:plistpath]; Nsarray *templist = [Self.dicdata AllKeys]; To sort key//selector to SEL type, the Sortedarrayusingselector method must be selector self.listgroupname = [Templist Sortedarrayusi Ngselector: @selector (compare:)];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} #pragma mark rewrite the data source Method-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{//According to the section cable Derive group name from group an array group nsstring *groupname = [Self.listgroupname objectatindex:section]; Take the group name as key and remove the team array from the dictionary//Because the hash structure nsarray *listteams = [self.dicdata objectforkey:groupname] when stored; //How many teams return [Listteams Count] in the same section;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static NSString *cellidentifier = @ "Cellidentifier"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:celli Dentifier]; }//Gets the selected section A group of 1th nsuinteger section = [indexpath sections]; Gets the row index selected in the selection section--Group A 1th, 2nd.。
Nsuinteger row = [Indexpath row]; Get the group name from the group an array group according to the section index--Group A nsstring *groupname = [Self.listgroupname objectatindex:section]; Take the group name as key and remove the team array collection from the dictionary nsarray *listteams = [Self.dicdata objectforkey:groupname]; Cell.textLabel.text = [Listteams objectatindex:row]; return cell;} -(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{//The section number of rows return [Self.listgroupname count];} -(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{//section header of the section NSString *grou PName = [Self.listgroupname objectatindex:section]; return groupName;} -(Nsarray *) Sectionindextitlesfortableview: (UITableView *) tableview{//Join index Nsmutablearray *listtitles = [[NSMutab Learray Alloc] initwithcapacity:[self.listgroupname Count]]; Change Group A to (NSString *item in self.listgroupname) {nsstring *title = [item substringtoindex:1];//Get the first character [Listtitles Addobject:title]; Append the last position of the string array} return LISTTITLes;} @end
Attention:
In this story to configure the version TableView Trust Agreement ...!!
Join index (iOS development)