2013-04-20 145 views
-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; 
    } 

回答

1

如果我理解你 -

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

相關問題