gpt4 book ai didi

ios - AF网络 block 和提要

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

好吧,我还有另一个问题,今晚,使用 AFNetworking,我解析我的 JSON Stream,添加一个 MutableArray 对象,当我插入尝试在成功 block 之外打印数组时,它说 null,但在这个 block 内部它有效,那么我如何将 _listOfNewsArray 传递到主线程中?

这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"bgWhitelight" ofType:@"png"];
self.tableView.backgroundColor = [[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:path]];

NSURLRequest *newsRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://aXXXXXXXXXXXipt/beta.php"]];

AFJSONRequestOperation *newsJSONRequest = [AFJSONRequestOperation JSONRequestOperationWithRequest:newsRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSArray *newsArray = [JSON objectForKey:@"news"];
_listOfNews = [[NSMutableArray alloc]init];

for (NSDictionary *oneNews in newsArray) {

CCENews *currentNews = [[CCENews alloc]init];
currentNews.title = [oneNews objectForKey:@"title"];
currentNews.content = [oneNews objectForKey:@"content"];
currentNews.category = [currentNews getHiResCategoryPicture:[oneNews objectForKey:@"category"]];
currentNews.date = [oneNews objectForKey:@"date"];
currentNews.imageURL = [oneNews objectForKey:@"pictureurl"];

[_listOfNews addObject:currentNews];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

NSLog(@"%@", error);
}];

[newsJSONRequest start];

最佳答案

事实上,我找到了解决方案,只需使用 self.listOfNews,只需考虑一下即可!-

关于ios - AF网络 block 和提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16125820/

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