【问题标题】:Parsing retweet profile image解析转发个人资料图片
【发布时间】:2013-04-20 20:26:15
【问题描述】:

我正在开发一个显示 Twitter 用户时间线的应用程序。 UITableView 包含具有推文、时间和个人资料图标的单元格。但是,转推仍然有用户的个人资料图像,而不是原始海报的图像。 JSON 文件添加了一个名为 retweeted_status 的新密钥,该密钥具有一个名为 user 的密钥,其中包含配置文件图像 URL 内容。如何做出条件语句来查找 retweeted_status 是否存在。如果没有,则获取图像,如下代码所示:

 static NSString *CellIdentifier = @"Cell";

 UITableViewCell *cell = [self.tweetTableView
 dequeueReusableCellWithIdentifier:CellIdentifier];

 if (cell == nil) {
 cell = [[UITableViewCell alloc]
 initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
 }

dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
dispatch_async(downloadQueue, ^{
    NSDictionary *tweet =_dataSource[[indexPath row]];
    NSDictionary *tweetSubtitle = _dataSource[[indexPath row]];

    //NSURL *retweetURL = [NSURL URLWithSting: [[tweet objectForKey:@"retweeted_status"] objectForKey:@"user"] objectForKey:@"profile_image_url"];


    NSURL *imageURL = [NSURL URLWithString:[[tweet  objectForKey:@"user"]objectForKey:@"profile_image_url"]];
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];

    //Need conditional function to find if retweet

    //NSLog(@"%@",imageData);
    dispatch_async(dispatch_get_main_queue(), ^{


        cell.textLabel.text = tweet[@"text"];
        cell.detailTextLabel.text = tweetSubtitle[@"created_at"];


        cell.imageView.image = [UIImage imageNamed:@"placeholder"];
        cell.imageView.image = [UIImage imageWithData:imageData];
    });
});
   //NSLog(@"screen name %@", tweetSubtitle[@"screen_name"]);

 return cell;
  }

【问题讨论】:

    标签: ios objective-c json parsing uitableview


    【解决方案1】:

    如果我理解你 -

    if ([tweet objectForKey:@"retweeted_status"])
    {
    // the tweet has a retweeted status
    }
    else
    {
    // no retweeted status
    }
    

    我说的对吗?这就是你想要的?

    【讨论】:

    • 是的,这就是我想要得到的。
    • 那么我写的代码有什么问题?我的意思是,这是检查元素是否存在的方法......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多