[Code Note] iOS-TableViewOfTwoSecton, code note

Source: Internet
Author: User

[Code Note] iOS-TableViewOfTwoSecton, code note

I ,.

2. Engineering Drawing.

3. Code.

RootViewController. h

#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{    NSArray * dataArray;    NSArray * aboutArray;}@end

 

RootViewController. m

# Import "RootViewController. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. title = @ "tableViewOfTwoSection"; // initialize the background image [self initBackGroundView]; // initialize the data [self initData];} # pragma-mark-funcitons-(void) initBackGroundView {UITableView * tableview = [[UITableView alloc] initWithFrame: CGRectMake (0, 0,320,376) style: UITableViewStyleGrouped]; tableview. delegate = self; tableview. dataSource = self; [self. view addSubview: tableview];}-(void) initData {dataArray = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjectsAndKeys: @ "brainstorming", @ "title", nil], [NSDictionary Syntax: @ "children's diet", @ "title", nil], [NSDictionary dictionaryWithObjectsAndKeys: @ "", @ "title", nil], [NSDictionary Syntax: @ "", @ "title", nil], nil]; aboutArray = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjectsAndKeys: @ "", @ "title ", @ "aboutViewController", @ "class", nil], nil] ;}# pragma-mark-UITableViewDelegate-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 2 ;} -(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {if (section = 0) {return dataArray. count;} else if (section = 1) {return aboutArray. count;} return 0;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [tableView progress: @ "ID"]; if (cell = nil) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: @ "ID"];} if (indexPath. section = 0) {cell. textLabel. text = [[dataArray objectAtIndex: indexPath. row] objectForKey: @ "title"]; cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator;} else if (indexPath. section = 1) {cell. textLabel. text = [[aboutArray objectAtIndex: indexPath. row] objectForKey: @ "title"]; cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator;} return cell;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {if (indexPath. section = 0) {if (indexPath. row = 0) {NSLog (@ "brainstorming");} else if (indexPath. row = 1) {NSLog (@ "children's diet");} else if (indexPath. row = 2) {NSLog (@ "");} else if (indexPath. row = 3) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "http://baby.163.com"] ;}} else if (indexPath. section = 1) {if (indexPath. row = 0) {NSLog (@ "about") ;}}- (void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end

Related Article

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.