gpt4 book ai didi

ios - 如何更快地下载新闻?

转载 作者:行者123 更新时间:2023-12-01 19:02:29 25 4
gpt4 key购买 nike

我有一个UITableViewController类,我在viewDidLoad方法中下载了代码。
该代码可以吗?我不太确定要下载和显示内容。因为显示新闻要花费很多时间,并且表格滚动滞后。抱歉,我是 objective-c 的新手。

@implementation NewsViewController
- (void)viewDidLoad
{


// _sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
[super viewDidLoad];
[self getJSON];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return currentCellsCount;
}

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

CellForNews *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

id tempObject=[self.arrayOfNews objectAtIndex:indexPath.row];
cell.publishDate.text=tempObject[@"publish_date"];
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:tempObject[@"img_path"]]];
cell.newsImage.image=[UIImage imageWithData:data];
cell.descriptionOfThenews.text=tempObject[@"body"];
cell.titleOfTheNews.text=tempObject[@"publish_title"];

return cell;
}

-(void)getJSON{

NSString *path=@"example.com";


NSURL *url=[NSURL URLWithString:path];

NSString *dataJSON=[NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:Nil];

NSData *data=[dataJSON dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *rootDictionary=[NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:nil];

NSDictionary *newsDict=[rootDictionary objectForKey:@"publications"];
id marker=[[NSObject alloc]init];
self.arrayOfNews=(NSMutableArray*)[newsDict objectsForKeys:[newsDict allKeys] notFoundMarker:marker];
currentCellsCount=[newsDict allKeys].count;


}

最佳答案

不要三思而后行。对于任何联网操作,请使用AFnetworking,对于任何图像Web加载,请使用SDWebImage

关于ios - 如何更快地下载新闻?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21928181/

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