UITableView中的两个自定义单元格

时间:2014-06-27 18:59:33

标签: ios uitableview

我正在尝试在UITableView中使用两个自定义单元格。我遇到的问题是我的回归没有在正确的地方被调用。我不确定我需要实现返回来阻止控件到达非void函数的末尾。

这是我的cellforrowatindex中的代码。

static NSString *kCellID = @"MessageCell";
static NSString *UCellID = @"UnreadCell";
if (status == 0)
{
    //static NSString *kCellID = @"MessageCell";
    MessageListCell *cell = (MessageListCell *) [tableView dequeueReusableCellWithIdentifier:kCellID];

        if (priority == 0)
        {
            cell. imageviewImportance.image = nil;
        }
        if (priority == 1)
        {
            cell.imageviewImportance.image = [UIImage imageNamed:@"single exclamation.png"];
        }
        if (priority == 2)
        {
            cell.imageviewImportance.image = [UIImage imageNamed:@"double exclamation mark.png"];
        }
        if (priority == 3)
        {
            cell.imageviewImportance.image = [UIImage imageNamed:@"triple exclamation kmar.png"];
        }
//if (status == 0)
//{
    cell.backgroundColor = [UIColor clearColor];
    cell.labelFrom.text = [NSString stringWithFormat:@"From: %@",m.From];
    cell.labelFrom.font = [UIFont boldSystemFontOfSize:17];
    cell.labelSubject.text = subject;
    cell.labelSubject.font = [UIFont boldSystemFontOfSize:17];
    cell.labelTime.text = time;
    cell.labelTo.text = [NSString stringWithFormat:@"To: %@",m.To];
    cell.labelTo.font = [UIFont boldSystemFontOfSize:17];
    return cell;
}
else if (status != 0)
{
    //static NSString *UCellID = @"UnreadCell";
    MessageListCell *cell = (MessageListCell *)[tableView dequeueReusableCellWithIdentifier:UCellID];
    cell.backgroundColor = [UIColor clearColor];
    cell.unreadLabelFrom.text = [NSString stringWithFormat:@"From: %@",m.From];
    cell.unreadLabelSubject.text = subject;
    cell.unreadLabelTo.text = [NSString stringWithFormat:@"To:%@",m.To];
    cell.unreadLabelTime.text = time;
    return cell;
}
//NSLog(@"description = %@",[cell description]);
//return cell;

}

1 个答案:

答案 0 :(得分:0)

只需将else if更改为else,编译器就会停止抱怨。

你现在拥有它的方式是告诉编译器检查2条件,如果没有满足它们会怎么样?什么会被退回?

您需要else阻止,但由于else if是多余的,因此您需要else


if (status == 0)
{
    static NSString *kCellID = @"MessageCell";
    MessageListCell *cell = (MessageListCell *) [tableView dequeueReusableCellWithIdentifier:kCellID];

    NSString *imageName;
    switch (priority) {
        case 0:
            imageName = nil;
            break;
        case 1:
            imageName = @"single exclamation.png";
            break;
        case 2:
            imageName = @"double exclamation mark.png";
            break;
        case 3:
            imageName = @"triple exclamation kmar.png";
            break;
        default:
            break;
    }


    cell.imageviewImportance.image = [UIImage imageNamed:imageName];
    cell.backgroundColor = [UIColor clearColor];
    cell.labelFrom.text = [NSString stringWithFormat:@"From: %@",m.From];
    cell.labelFrom.font = [UIFont boldSystemFontOfSize:17];
    cell.labelSubject.text = subject;
    cell.labelSubject.font = [UIFont boldSystemFontOfSize:17];
    cell.labelTime.text = time;
    cell.labelTo.text = [NSString stringWithFormat:@"To: %@",m.To];
    cell.labelTo.font = [UIFont boldSystemFontOfSize:17];
    return cell;
}
else
{
    static NSString *UCellID = @"UnreadCell";
    MessageListCell *cell = (MessageListCell *)[tableView dequeueReusableCellWithIdentifier:UCellID];
    cell.backgroundColor = [UIColor clearColor];
    cell.unreadLabelFrom.text = [NSString stringWithFormat:@"From: %@",m.From];
    cell.unreadLabelSubject.text = subject;
    cell.unreadLabelTo.text = [NSString stringWithFormat:@"To:%@",m.To];
    cell.unreadLabelTime.text = time;
    return cell;
}