我想知道如何将图像放在自定义单元格的背景上
我使用的代码是这个,但是这会将所有表格设置为相同的图像我希望每个单元格都有自己的背景,具体取决于谁是消息所有者我希望你能帮助我,这正在杀死我!
- (UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[self.messageList dequeueReusableCellWithIdentifier:@"ChatListItem"];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChatListItem" owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}
NSDictionary *itemAtIndex = (NSDictionary *)[messages objectAtIndex:indexPath.row];
UILabel *textLabel = (UILabel *)[cell viewWithTag:1];
textLabel.text = [itemAtIndex objectForKey:@"text"];
UILabel *userLabel = (UILabel *)[cell viewWithTag:2];
userLabel.text = [itemAtIndex objectForKey:@"user"];
if(usernameText=userLabel){
UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chat2@2x.png"]];
[cell setBackgroundView:img];
[img release];
}
else{
UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chat1@2x.png"]];
[cell setBackgroundView:img];
[img release];
}
return cell;
}