-1
我正在研究顯示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;
}
是的,那就是我想要得到的。 – DaveLass 2013-04-20 20:43:43
那麼我寫的代碼有什麼問題?我的意思是,這是檢查元素是否存在的方法... – 2013-04-20 20:47:44