开发者

segment control not working in iphone

I am a new bie and using segment controlller to see the table and my table changes according to the selected segment...

here is the code...and problem is when I select any segment..it is not showing me anything..

   - (void)viewDidLoad {

segArrayOne = [[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",nil];
segArrayTwo = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",nil];
segArrayThree = [[NSMutableArray alloc] initWithObjects:@"A1",@"A2",@"A3",@"A4",@"A5",nil]开发者_如何学Go;
dummyArray = [[NSMutableArray alloc] init]; 

tableDummy = [[UITableView alloc] initWithFrame:CGRectMake(0,80,320,400) style:UITableViewStyleGrouped];
tableDummy.delegate = self;
tableDummy.dataSource = self;
//
dummyArray=segArrayOne; 
[self.view addSubview:tableDummy];
tableDummy.scrollEnabled=NO;

//[tableDummy release];
[segmentedController addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventValueChanged];


[super viewDidLoad];

}

 -(IBAction)buttonPressed:(id)sender{

selectedSegment = [segmentedController selectedSegmentIndex];

switch (selectedSegment) {
    case 0:
        dummyArray=segArrayOne; 
        break;
    case 1:
        dummyArray=segArrayTwo;
        break;
    case 2:
        dummyArray=segArrayThree;

        break;  
    default:
        //dummyArray=segArrayOne;

        break;
}


NSLog(@"%@",dummyArray);

}

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;

}

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%@",dummyArray);

return [dummyArray count];
//return @"";

}

             - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
cell.textLabel.text = [dummyArray objectAtIndex:indexPath.row];

return cell;

}


Call [tableDummy reloadData] at the end of

-(IBAction)buttonPressed:(id)sender

or in the cases if you'd like to duplicate code and don't want to reloadData in a default case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜