我想知道我怎樣才能把圖片上的代碼即時通訊使用的自定義單元格在自定義TableViewCell設置圖像
的背景是這樣的,但這種設置所有表相同的圖像 我希望每個細胞都有自己的背景,具體取決於誰是消息所有者 我希望你能幫助我,這就是殺了我!
- (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:@"[email protected]"]];
[cell setBackgroundView:img];
[img release];
}
else{
UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"[email protected]"]];
[cell setBackgroundView:img];
[img release];
}
return cell;
}
請不要添加簽名 – user427969