Ios 仅使用媒体url检索推文

Ios 仅使用媒体url检索推文,ios,objective-c,twitter,Ios,Objective C,Twitter,我目前正在开发一个应用程序,我只想加载包含媒体url的推文。我已经尝试阻止它将推文加载到tableView中,但是由于明显的原因,这会导致大量空白推文 我使用的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableVi

我目前正在开发一个应用程序,我只想加载包含媒体url的推文。我已经尝试阻止它将推文加载到tableView中,但是由于明显的原因,这会导致大量空白推文

我使用的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    id tweet = [self.timeline objectAtIndex:[indexPath row]];

    NSString *example = [NSString stringWithFormat:@"%@",[tweet valueForKeyPath:@"entities.media.media_url"]];
    NSLog(@"%@", example);

    if ([example isEqual: @"(null)"] ) {

    } else {
        cell.textLabel.text = [tweet valueForKeyPath:@"text"];
        cell.detailTextLabel.text = [tweet valueForKeyPath:@"user.name"];
    }

    return cell;
}
所以现在我正在寻找另一种方法,它只会成功加载有媒体url的tweet,并按它们出现的顺序排列。我正在使用NSJSONSerialization来解析我的数据

我使用的代码:

- (void)fetchData
{
    [_refreshHeaderView refreshLastUpdatedDate];
    NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/home_timeline.json?count=199&include_entities=true"];
    TWRequest *request = [[TWRequest alloc] initWithURL:url 
                                                 parameters:nil 
                                              requestMethod:TWRequestMethodGET];
    [request setAccount:self.account];    
    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        if ([urlResponse statusCode] == 200) {
            NSError *jsonError = nil;
            id jsonResult = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];
            if (jsonResult != nil) {
                self.timeline = jsonResult;
                dispatch_sync(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData];
                });                
            }
            else {
                NSString *message = [NSString stringWithFormat:@"Could not parse your timeline: %@", [jsonError localizedDescription]];
                [[[UIAlertView alloc] initWithTitle:@"Error" 
                                            message:message
                                           delegate:nil 
                                  cancelButtonTitle:@"Cancel" 
                                  otherButtonTitles:nil] show];
            }
        }
    }];
   [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1.0];  
}
所以我想知道,我是否可以制作添加到时间线中的数据,只制作那些包含媒体url的推特,或者是否有更好的方法使用不同的方法来实现这一点


谢谢。

也许可以尝试使用类似的方法来检查tweet是否包含媒体url:

if([tweet valueForKey:@"entities.media.media_url"] == [NSNull null])