The effect is as follows:
ViewController.h
1 #import <UIKit/UIKit.h>23@interface viewcontroller: Uitableviewcontroller4 @property (Strong, Nonatomic) Nsmutablearray *marrredflowername; 5 @property (Strong, Nonatomic) Nsmutablearray *marrblueflowername; 6 7 @end
Viewcontroller.m
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4- (void) Layoutui;5 @end6 7 @implementationViewcontroller8 #defineKflowercount 79 #defineKredflowertype 0Ten #defineKblueflowertype 1 One A- (void) Viewdidload { - [Super Viewdidload]; - the [self layoutui]; - } - -- (void) didreceivememorywarning { + [Super didreceivememorywarning]; - //Dispose of any resources the can be recreated. + } A at- (void) Layoutui { -Self.navigationItem.title =@"Split Table View"; - -_marrredflowername =[[Nsmutablearray alloc] initwithcapacity:kflowercount]; -_marrblueflowername =[[Nsmutablearray alloc] initwithcapacity:kflowercount]; - for(Nsinteger i=1; i<=kflowercount; i++) { in[_marrredflowername addobject:[nsstring stringWithFormat:@"redflower%ld", (Long) [i]]; -[_marrblueflowername addobject:[nsstring stringWithFormat:@"blueflower%ld", (Long) [i]]; to } + } - the #pragmaMark-tableview *-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) Section { $NSString *strtitle =@"";Panax Notoginseng Switch(section) { - CaseKredflowertype: theStrtitle =@"Red Flowers"; + Break; A CaseKblueflowertype: theStrtitle =@"Blue Flowers"; + Break; - } $ returnstrtitle; $ } - --(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView { the return 2; - }Wuyi the-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section { - returnKflowercount; Wu } - About-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath { $ StaticNSString *cellidentifier =@"Cellidentifier"; -UITableViewCell *cell =[TableView Dequeuereusablecellwithidentifier:cellidentifier]; - if(!cell) { -Cell =[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; A } + the Switch(indexpath.section) { - CaseKredflowertype: $Cell.textLabel.text =_marrredflowername[indexpath.row]; the Break; the CaseKblueflowertype: theCell.textLabel.text =_marrblueflowername[indexpath.row]; the Break; - } inCell.imageView.image =[UIImage ImageNamed:cell.textLabel.text]; the returncell; the } About the- (void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath { theNSString *strmessage =@""; the Switch(indexpath.section) { + CaseKredflowertype: -strmessage = [NSString stringWithFormat:@"Red flower:%@", _marrredflowername[indexpath.row]]; the Break;Bayi CaseKblueflowertype: thestrmessage = [NSString stringWithFormat:@"Blue flower:%@", _marrblueflowername[indexpath.row]]; the Break; - } -Uialertview *alertvcustom = [[Uialertview alloc] Initwithtitle:@"Select Information" the Message:strmessage the Delegate: Nil the Cancelbuttontitle:nil theOtherbuttontitles:@"Determine", nil]; - [Alertvcustom show]; the } the the @end
AppDelegate.h
1 #import <UIKit/UIKit.h>23@interface Appdelegate:uiresponder < Uiapplicationdelegate>4 @property (Strong, Nonatomic) UIWindow *window; 5 @property (Strong, Nonatomic) Uinavigationcontroller *Navigationcontroller; 6 7 @end
Appdelegate.m
1 #import "AppDelegate.h"2 #import "ViewController.h"3 4 @interfaceappdelegate ()5 @end6 7 @implementationappdelegate8 9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Ten_window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; OneViewcontroller *viewcontroller =[[Viewcontroller alloc] init]; A_navigationcontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; -_window.rootviewcontroller =_navigationcontroller; - //[_window Addsubview:_navigationcontroller.view];//when _window.rootviewcontroller is associated, this sentence is optional the [_window makekeyandvisible]; - returnYES; - } - +- (void) Applicationwillresignactive: (UIApplication *) Application { - } + A- (void) Applicationdidenterbackground: (UIApplication *) Application { at } - -- (void) Applicationwillenterforeground: (UIApplication *) Application { - } - -- (void) Applicationdidbecomeactive: (UIApplication *) Application { in } - to- (void) Applicationwillterminate: (UIApplication *) Application { + } - the @end
115 Split Table view