解析转推个人资料图片

问题描述:

我正在研究显示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; 
    } 

如果我理解你 -

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

是吗?这是你想要的吗?

+0

是的,那就是我想要得到的。 – DaveLass 2013-04-20 20:43:43

+0

那么我写的代码有什么问题?我的意思是,这是检查元素是否存在的方法... – 2013-04-20 20:47:44