//
 
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
 
}