uitableview问题

时间:2011-06-26 14:31:17

标签: iphone xcode uitableview

我尝试这种情况但不起作用。如果senderlabel = key @“sender”,则为每行使用green.png或grey.png。

    if (senderLabel.text = [tempMsg objectForKey:@"sender"]) 
    {
        [cell.msgText setText:[tempMsg objectForKey:@"message"]];

        [messTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        //[cell setFrame:CGRectMake(0,0, size.width, size.height)];
        [cell.msgText setFrame:CGRectMake(15,3, size.width, result)]; 




        UIImage* balloon = [[UIImage imageNamed:@"grey.png"] stretchableImageWithLeftCapWidth:24  topCapHeight:15];
        UIImageView *newImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, size.width+10, result+10)];
        UIView *newView =[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height)];

        [newImage setImage:balloon];
        [newView addSubview:newImage];
        [cell setBackgroundView:newView];

    }else {
        [cell.msgText setText:[tempMsg objectForKey:@"message"]];

        [messTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        //[cell setFrame:CGRectMake(0,0, size.width, size.height)];
        [cell.msgText setFrame:CGRectMake(15,3, size.width, result)]; //propriété du texte


        UIImage* balloon = [[UIImage imageNamed:@"green.png"] stretchableImageWithLeftCapWidth:24  topCapHeight:15];
        UIImageView *newImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, size.width+10, result+10)];
        UIView *newView =[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height)];

        [newImage setImage:balloon];
        [newView addSubview:newImage];
        [cell setBackgroundView:newView];

    }



    return cell;

}

3 个答案:

答案 0 :(得分:0)

if(senderLabel.text = [tempMsg objectForKey:@“sender”])不正确。您需要在比较中使用isEqual。

if ([senderLabel.text isEqual:[tempMsg objectForKey:@"sender"]])

答案 1 :(得分:0)

首先,这里

if (senderLabel.text = [tempMsg objectForKey:@"sender"])

你正在做作业,而不是比较,比较是

if (senderLabel.text == [tempMsg objectForKey:@"sender"])

然而,如果它是内存中完全相同的对象,那可能会比较,这可能不是你想要的,如果你想检查字符串是否有相同的文字,你必须使用

[string isEqualToString:anotherString]

答案 2 :(得分:0)

要获得indexpath,您可以像这样使用:

NSIndexPath *indexpath = [NSIndexPath indexPathForRow:0 inSection:0];

并进行比较:

if ([string compare:anotherString] == NSOrderedSame)