选择 UISegment 控件时更改 UITableViewCell 标签

change UITableViewCell lable when selecting UISegment Control

当我更改到段控件上的不同部分时,我试图更改 table 视图单元格标签,但是更改段接缝无济于事,我们将不胜感激

  1. 通过故事板将段控制拖到导航控制器
  2. 创建一个 iboutlet 属性 并将其链接到段控制器
  3. 将下面的代码添加到我的 viewDidLoad

[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 显示了我选择的片段,但是 table视图单元格根本没有改变。

您是否将 Target 添加到 segmentedControl?

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

然后

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