1

我正在使用 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 。

请帮忙..

4

3 回答 3

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"];
于 2013-08-11T12:28:56.523 回答
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"];
于 2015-07-31T12:21:33.053 回答
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"];
            });
        });
于 2015-07-31T13:15:51.397 回答