Advanced Control table view in IOS
Step 1: drag the control and connect the data source, so I can't take the previous image directly. If you do not understand, click connection 010 to create an ios6.0 application on xcode4.5.
(Advanced control table view basic table view)
Step 2: edit the H file to implement the table control protocol viewcontroller. h
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{ NSDictionary *dictionary; NSArray *arr;}@property(nonatomic,retain)NSDictionary *dictionary;@property(nonatomic,retain)NSArray *arr;@end
Viewcontroller. m
@ Implementation viewcontroller @ synthesize dictionary; @ synthesize arr; // method used to represent Graphs-(void) tableview :( uitableview *) tableview didselectrowatindexpath :( nsindexpath *) indexpath {nsuinteger section = [indexpath section]; nsuinteger ROW = [indexpath row]; nsstring * name = [arr objectatindex: section]; nsarray * team = [dictionary objectforkey: Name]; nsstring * selectedteam = [Team objectatindex: Row]; nsstring * message = [[nsstring alloc] initwithformat: @ "your selected number is % @", selectedteam]; uialertview * Alert = [[uialertview alloc] initwithtitle: @ "team selection" message: Message delegate: Self cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil]; [alert show]; [alert release]; [Message release]; // when you click it, the selected one will gradually disappear [tableview deselectrowatindexpath: indexpath animated: Yes];} // implement index-(nsarray *) sectionindextitlesfortableview :( uitableview *) tableview {return arr;}-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) section {// The return segment contains several lines nsstring * name = [arr objectatindex: section]; nsarray * team = [dictionary objectforkey: Name]; return [team count];} // return quantity-(nsinteger) numberofsectionsintableview :( uitableview *) tableview {return [arr count];} // return the name in each segment-(nsstring *) tableview :( uitableview *) tableview titleforheaderinsection :( nsinteger) Section {nsstring * name = [arr objectatindex: section]; return name;}-(uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {static nsstring * cellidentifier = @ "cell"; uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier: cellidentifier]; If (cell = nil) {Cell = [[uitableviewcell alloc] initwithstyle: uitableviewcellstyledefault reuseidentifier: cellidentifier] autorelease];} nsuinteger section = [indexpath section]; nsuinteger ROW = [indexpath row]; nsstring * name = [arr objectatindex: section]; nsarray * team = [dictionary objectforkey: Name]; // return protocol title cell. textlabel. TEXT = [Team objectatindex: Row]; return cell;}-(void) viewdidload {[Super viewdidload]; // The following Code reads the file to the Code in the mode code. nsbundle * bundle = [nsbundle mainbundle]; nsstring * filepath = [bundle pathforresource: @ "statedictionary" oftype: @ "plist"]; nsdictionary * DIC = [[nsdictionary alloc] initwithcontentsoffile: filepath]; self. dictionary = DIC; [DIC release]; // query the content in the dictionary by ID and sort self. arr = [[dictionary allkeys] sortedarrayusingselector: @ selector (compare :)];}-(void) Detail {[Super didreceivememorywarning]; // dispose of any resources that can be recreated .} -(void) dealloc {[dictionary release]; [arr release]; [Super dealloc];} @ end
Finally, we implemented the segment table view.
To implement the grouping table view, you only need to modify one attribute on the basis of the segmentation table view.
As you can see, the above view has an index implementation, which is relatively simple. You only need to implement this small code.
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return arr;}