gpt4 book ai didi

ios - 仅使用 media_url 检索推文

转载 作者:行者123 更新时间:2023-11-29 03:53:42 25 4
gpt4 key购买 nike

我目前正在开发一个应用程序,我只想加载包含 media_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;
}

所以现在我正在寻找一种替代方法,该方法只能成功加载具有 media_url 的推文,并将它们按出现的顺序排列。我正在使用 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];
}

所以我想知道我是否可以将数据添加到时间线中,只有那些包含 media_url 的推文,或者是否有更好的方法使用不同的方法来做到这一点。

谢谢。

最佳答案

也许尝试使用类似的方法来检查推文是否包含媒体网址:

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

关于ios - 仅使用 media_url 检索推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16773988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com