【问题标题】:How can i show user avatar image using xmpp framework in objective c?如何在目标 c 中使用 xmpp 框架显示用户头像图像?
【发布时间】:2013-07-31 08:04:00
【问题描述】:

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

请帮忙..

【问题讨论】:

  • 什么返回 nil ?照片数据?
  • if (photoData) cell.imageView.image = [UIImage imageWithData:photoData];

标签: iphone ios objective-c xmppframework


【解决方案1】:
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"];

【讨论】:

    【解决方案2】:

    这段代码运行良好。

    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"];
    

    【讨论】:

      【解决方案3】:
      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"];
                  });
              });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-08
        • 2016-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-30
        • 1970-01-01
        • 2018-07-07
        相关资源
        最近更新 更多