change UITableViewCell lable when selecting UISegment Control

108 views Asked by At

im trying to change the table view cell labels when i change to a different section on the segment control, however changing the segments seams to do nothing, any help would be appreciated

  1. dragged segment control to the nav controller via storyboard
  2. made an iboutlet property and linked it to the segment controller
  3. added the code below to my viewDidLoad

[segmentedControl addTarget:self action:@selector(cycleButton:) forControlEvents:UIControlEventValueChanged];

4 added this method

- (void)cycleButton:(id)sender {
CustomCell *cell = [[CustomCell alloc]init];
SSVCYLY *cellLabel = [[SSVCYLY alloc]init];


if (self.segmentedControl.selectedSegmentIndex == 0) { //Total
    NSLog(@"Total Selected");
    cell.dum.text = [NSString stringWithFormat:@"Total: %@", cellLabel.TOTAL];
    //cell.dumcc.text =

    cell.vdum.text = [NSString stringWithFormat:@"VTotal: %@", cellLabel.VTOTAL];
    //cell.vdumcc.text =

    cell.ldum.text = [NSString stringWithFormat:@"LTotal: %@", cellLabel.ltotal];
    //cell.ldumcc.text =


} else (self.segmentedControl.selectedSegmentIndex == 1) { //Bakery
    NSLog(@"Bakery Selected");
    cell.dum.text = [NSString stringWithFormat:@"Bak: %@", cellLabel.BAK];
    cell.dumcc.text = [NSString stringWithFormat:@"Bakcc: %@", cellLabel.bakcc];
    cell.vdum.text = [NSString stringWithFormat:@"VBak: %@", cellLabel.VBAK];
    cell.vdumcc.text = [NSString stringWithFormat:@"VBakcc: %@", cellLabel.VBAKCC];
    cell.ldum.text = [NSString stringWithFormat:@"LBak: %@", cellLabel.lbak];
    cell.ldumcc.text = [NSString stringWithFormat:@"LBakcc: %@", cellLabel.lbakcc];


} 

NSLog shows what segment ive selected, but the tableview cells dont change at all.

1

There are 1 answers

1
Reming Hsu On BEST ANSWER

Did you add Target to segmentedControl?

[segmentedControl addTarget:self
                     action:@selector(actionMethod:)
           forControlEvents:UIControlEventValueChanged];

then

- (void)actionMethod:(id)sender
{
    //reload your table
}