iOS Survival Road II (click Segment Management TableView)

Source: Internet
Author: User

//

Viewcontroller.m

Segment

//

Created by Jessewang on 5/23/12.

Copyright (c) __mycompanyname__. All rights reserved.

//


#import "ViewController.h"

#define KFIRSTSEGMENTEDINDEX 0

#define KSECONDSEGMENTEDINDEX 1

@implementation Viewcontroller

@synthesize segmented;

@synthesize Firsttableview;

@synthesize Secondtableview;


-(void) didreceivememorywarning

{

[Super didreceivememorywarning];

Release any cached of data, images, etc that aren ' t in use.

}


#pragma mark-view lifecycle


-(void) viewdidload

{

[Super Viewdidload];

Do no additional setup after loading the view, typically from a nib.

}


-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section

{

Switch (segmented.selectedsegmentindex) {

Case Kfirstsegmentedindex:

{

return 3;

}

Break

Case Ksecondsegmentedindex:

{

return 8;

}

Break

Default

return 0;

Break

}

}




-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (nsindexpath*) IndexPath

{

Nsuinteger row = [Indexpath row];

Switch (segmented.selectedsegmentindex) {

Case Kfirstsegmentedindex:

{

static NSString *cell1 = @ "FirstCell";

UITableViewCell *firstcell = [TableView dequeuereusablecellwithidentifier:cell1];

if (FirstCell = = nil) {

FirstCell = [[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cell1] autorelease];

}

FirstCell.textLabel.text = @ "Firsttableview";

Return FirstCell;

}

Break

Case Ksecondsegmentedindex:

{

static NSString *cell2 = @ "Secondcell";

UITableViewCell *secondcell = [TableView dequeuereusablecellwithidentifier:cell2];

if (Secondcell = = nil) {

Secondcell = [[[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cell2] autorelease] ;

}

SecondCell.textLabel.text = @ "Secondtableview";

return Secondcell;

}

Break


Default

{

NSString *str = [NSString stringwithformat:@ "str%d", row];

UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:str];

if (cell = = nil) {

cell = [[[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:str] autorelease];

}

return cell;

}

Break

}

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.