Iphone 更改数据后重新加载自定义单元格时出错

Iphone 更改数据后重新加载自定义单元格时出错,iphone,xcode,uitableview,sdk,cell,Iphone,Xcode,Uitableview,Sdk,Cell,我有一个设置好的tableView,它工作得很好。 如下所示,当对象@“sent”的值更改为@“yes”时,我想在单元格中添加一个图像。完成后,我调用[sendTable reloadData],但tableView没有任何变化。只有当我重新启动应用程序时,我的图像才会正确显示在单元格中。 很明显,重新加载数据在这里没有任何作用 有人能解决这个问题吗 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndex

我有一个设置好的tableView,它工作得很好。 如下所示,当对象@“sent”的值更改为@“yes”时,我想在单元格中添加一个图像。完成后,我调用[sendTable reloadData],但tableView没有任何变化。只有当我重新启动应用程序时,我的图像才会正确显示在单元格中。 很明显,重新加载数据在这里没有任何作用

有人能解决这个问题吗

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell;

if (tableView == sendTable) {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"savedItems.plist"];
    savedItemsArray = [NSMutableArray arrayWithContentsOfFile:writableDBPath];

    NSDictionary* item = [savedItemsArray objectAtIndex:indexPath.row];

    NSString *temp = [NSString stringWithFormat:@"%@,%@", [[savedItemsArray valueForKey:@"name"]objectAtIndex:indexPath.row],
                      [[savedItemsArray valueForKey:@"message"]objectAtIndex:indexPath.row]];

    UIView *background;

    cell = [self.sendTable dequeueReusableCellWithIdentifier:temp];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:temp];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.selectionStyle = UITableViewCellSelectionStyleGray;

        background = [[UIView alloc] initWithFrame:cell.frame];

        [cell addSubview:background];
        [cell sendSubviewToBack:background];

    }

    if ([[item objectForKey:@"sent"] isEqualToString: @"no"]) {

        UILabel *personLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, cell.frame.size.width-150, 20)];
        personLabel.backgroundColor = [UIColor clearColor];
        personLabel.text = [NSString stringWithFormat: @"%@",[item objectForKey:@"name"]];
        personLabel.font = [UIFont boldSystemFontOfSize:17];

        UILabel *personLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, cell.frame.size.width-150, 20)];
        personLabel2.backgroundColor = [UIColor clearColor];
        personLabel2.text = [NSString stringWithFormat: @"(%@)", [item objectForKey:@"number"]];
        personLabel2.font = [UIFont systemFontOfSize:15];

        UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(cell.frame.size.width-125, 10, 80, 40)];
        dateLabel.backgroundColor = [UIColor clearColor];
        dateLabel.text = [NSString stringWithFormat: @"%@\n%@",[item objectForKey:@"date"], [item objectForKey:@"time"]];
        dateLabel.textColor = [UIColor darkGrayColor];
        dateLabel.textAlignment = NSTextAlignmentRight;
        dateLabel.font = [UIFont systemFontOfSize:13];
        dateLabel.numberOfLines = 2;

        UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 60, cell.frame.size.width-50, 20)];
        messageLabel.backgroundColor = [UIColor clearColor];
        messageLabel.text = [NSString stringWithFormat: @"%@",[item objectForKey:@"message"]];
        messageLabel.textColor = [UIColor lightGrayColor];
        messageLabel.font = [UIFont systemFontOfSize:15];

        [background addSubview:personLabel];
        [background addSubview:personLabel2];
        [background addSubview:dateLabel];
        [background addSubview:messageLabel];
        [cell addSubview:background];

    }else{

        UILabel *personLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 10, cell.frame.size.width-170, 20)];
        personLabel.backgroundColor = [UIColor clearColor];
        personLabel.text = [NSString stringWithFormat: @"%@",[item objectForKey:@"name"]];
        personLabel.font = [UIFont boldSystemFontOfSize:17];

        UILabel *personLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(40, 30, cell.frame.size.width-170, 20)];
        personLabel2.backgroundColor = [UIColor clearColor];
        personLabel2.text = [NSString stringWithFormat: @"(%@)", [item objectForKey:@"number"]];
        personLabel2.font = [UIFont systemFontOfSize:15];

        UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(cell.frame.size.width-125, 10, 80, 40)];
        dateLabel.backgroundColor = [UIColor clearColor];
        dateLabel.text = [NSString stringWithFormat: @"%@\n%@",[item objectForKey:@"date"], [item objectForKey:@"time"]];
        dateLabel.textColor = [UIColor darkGrayColor];
        dateLabel.textAlignment = NSTextAlignmentRight;
        dateLabel.font = [UIFont systemFontOfSize:13];
        dateLabel.numberOfLines = 2;

        UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 60, cell.frame.size.width-80, 20)];
        messageLabel.backgroundColor = [UIColor clearColor];
        messageLabel.text = [NSString stringWithFormat: @"%@",[item objectForKey:@"message"]];
        messageLabel.textColor = [UIColor lightGrayColor];
        messageLabel.font = [UIFont systemFontOfSize:15];

        UIImage *checkmarkImage = [UIImage imageNamed:@"done.png"];
        UIImageView *checkmark = [[UIImageView alloc] initWithImage:checkmarkImage];
        [checkmark setFrame:CGRectMake(10, 35, 20, 20)];

        [background addSubview:personLabel];
        [background addSubview:personLabel2];
        [background addSubview:dateLabel];
        [background addSubview:messageLabel];
        [background addSubview:checkmark];
        [cell addSubview:background];

    }

}
return cell;
}

非常感谢

当您将几个UILabel和UIView添加到一个单元格中时,我认为您应该自定义自己的UITableViewCell。 尝试创建一个子类UITableviewCell,并在实现中添加子视图。 希望我的回答有帮助