115 Split Table View

Source: Internet
Author: User

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

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.