我正在使用XMPPFramework为iPhone创建聊天应用程序。我想在UITableView中显示用户名和照片的用户列表,为此我正在使用
NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];
if (photoData != nil)
cell.imageView.image = [UIImage imageWithData:photoData];
else
cell.imageView.image = [UIImage imageNamed:@"blank_image~iPhone.png"];
但它总是返回nil。
请帮助..
答案 0 :(得分:3)
NSData *photoData = UIImagePNGRepresentation([[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid]);
if (photoData)
cell.imageView.image = [UIImage imageWithData:photoData];
else
cell.imageView.image = [UIImage imageNamed:@"blank_image~iPhone.png"];
答案 1 :(得分:0)
此代码工作正常。
photoDataForJID 方法返回NSData。
NSData *avtarData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];
if (avtarData)
cell.imageView.image = [UIImage imageWithData:photoData];
else
cell.imageView.image = [UIImage imageNamed:@"blank_image~iPhone.png"];
答案 2 :(得分:0)
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSData *imgData = UIImagePNGRepresentation([[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid]);
dispatch_async(dispatch_get_main_queue(), ^{
if (imgData)
cell.imageView.image = [UIImage imageWithData:imgData];
else
cell.imageView.image = [UIImage imageNamed:@"default_user.png"];
});
});