我面临的问题是我在 UItable 视图中有分段控制器,选择索引 0,它假设显示按钮(并且它工作完美)。问题是当我选择索引 1 并且表格视图改变了它的内容时,这里的按钮应该都被删除了。如果我添加这些语句,它只会删除最后一个单元格中的按钮
这些语句只是删除最后一个单元格的按钮
        [cell willRemoveSubview:downloadButton];
        [downloadButton removeFromSuperview];
        downloadButton.hidden=YES;
-(void)configureCell: (UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
    downloadButton = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [downloadButton setFrame:CGRectMake(250,8,30,30)];
    [downloadButton setTag :indexPath.row];
    [downloadButton setImage:[UIImage imageNamed:@"DownloadLesson.png"] forState:UIControlStateNormal];
    [downloadButton addTarget:self action:@selector(cellButton:) forControlEvents: UIControlEventTouchUpInside];
    if (segOL.selectedSegmentIndex==0) {
        [cell addSubview:downloadButton];
    } else {
        [cell willRemoveSubview:downloadButton];
        [downloadButton removeFromSuperview];
        downloadButton.hidden=YES;
    }
}
- (IBAction)cellButton:(id)sender {
    UIButton *play = sender;   
    NSLog(@"Number of row %d", play.tag]);
}