我正在按照以下方式从服务中获取数据,但是页面控制器没有刷新。
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.hidden = YES;
self.nElements = [[NSMutableArray alloc] init];
self.nTempElements = [[NSMutableArray alloc] init];
[self loadFromURL];
dispatch_async(dispatch_get_main_queue(), ^{
[self.pageController setViewControllers:[NSArray arrayWithObject:
[self
viewControllerAtIndex:0]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
});
}
-(void)loadFromURL {
if([self.nElements count]){
[self.nElements removeAllObjects];
}
if([self.nTempElements count]){
[self.nTempElements removeAllObjects];
}
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://www.xxxxx.com.tr/api/news.json" parameters:nil progress: nil success:^(NSURLSessionTask * _Nonnull operation, id responseObject) {
if(responseObject != NULL) {
for ( id jsonItem in [responseObject valueForKey:@"news"])
{
MainNewsData *dicItem = [[MainNewsData alloc]initWithDictionary:jsonItem];
[self.nElements addObject:dicItem];
[self.nTempElements addObject:[jsonItem valueForKey:@"resim"]];
}
}
} failure:^(NSURLSessionTask * _Nullable operation, NSError * _Nonnull error) {
}];
}
答案 0 :(得分:0)
您应该在主线程中调用函数-Ganesh-表示。
dispatch_async(dispatch_get_main_queue(), ^{
[self.pageController setViewControllers:[NSArray arrayWithObject:
[self
viewControllerAtIndex:0]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
});