011 create an ios6.0 application on xcode4.5 (advanced control table view segment table view)

Source: Internet
Author: User
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;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.