开发者

uitableview questions

i try to this condition but don't work. If the senderlabel = key@"sender" use the green.png or the grey.png for every rows.

    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:CGRectMak开发者_开发知识库e(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;

}


if (senderLabel.text = [tempMsg objectForKey:@"sender"]) is not correct. You need to use isEqual in your comparison.

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


First of all, here

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

you are making an assignment, not a comparison, comparing would be

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

However, that would compare if it's the exact same object in memory, which is probably not what you want, if you want to check if the string has the same text, you have to use

[string isEqualToString:anotherString]


To get indexpath you can use like this:

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

and for comparison:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜