选择UISegment控件时更改UITableViewCell标签

时间:2015-06-11 02:41:02

标签: ios objective-c uitableview uisegmentedcontrol

我试图更改表视图单元格标签,当我更改为段控件上的不同部分,但是更改段接缝什么都不做,任何帮助将不胜感激

  1. 通过故事板将段控制拖动到导航控制器
  2. 创建了一个iboutlet属性并将其链接到段控制器
  3. 将以下代码添加到我的viewDidLoad
  4. [segmentedControl addTarget:self action:@selector(cycleButton:) forControlEvents:UIControlEventValueChanged];

    4添加了此方法

    - (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显示我选择的片段,但是tableview单元格根本没有变化。

1 个答案:

答案 0 :(得分:0)

您是否将Target添加到segmentedControl?

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

然后

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