因此,我根据我的一个对象上的值是否 > 0 以编程方式创建 UIButton。但是,当我编辑该值并重新加载表时,它不会删除该按钮。该值绝对 > 0 而不是 nil,因为它显示在标签中。我尝试将按钮添加到每个单元格,然后设置其隐藏属性,这给了我与下面的代码相同的行为。如果我停止应用程序并重新运行应用程序,它会显示它应该如何运行。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
CGRect newIconRect = CGRectMake(280, 5, 33, 33);
UIButton *warningButton = [[UIButton alloc] initWithFrame:newIconRect];
warningButton.tag = 66;
[cell.contentView addSubview:warningButton];
}
UIButton *warningButton = (UIButton *)[cell.contentView viewWithTag:66];
[warningButton setImage:[UIImage imageNamed:@"exclamation.png"] forState:UIControlStateNormal];
[warningButton addTarget:self action:@selector(warningButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
if (ueo.daysLeft >= 0)
{
daysLeftLabel.text = [[NSString alloc]initWithFormat:@"%i recurringDays to go", ueo.daysLeft];
warningButton.hidden = YES;
}
else
{
daysLeftLabel.text = [[NSString alloc]initWithFormat:@"%i recurringDays have passed", ueo.daysLeft];
warningButton.hidden = NO;
}
}