gpt4 book ai didi

AFNetworking 的 iOS block 问题

转载 作者:行者123 更新时间:2023-11-28 21:43:25 25 4
gpt4 key购买 nike

我目前正在学习积木,我想将它们与 AFNetworking 一起使用。我在 Singletone 中制作了方法:

- (void)getAllPlayers:(void (^)(NSArray *playerz, bool succeed))blockPlayers {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"https://api.myjson.com/bins/530re" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {



} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];

}

我在 viewDidLoad 中调用了这个方法:

[[Manager sharedInstance]getAllPlayers:^(NSArray *playerz, bool succeed) {
if (succeed == YES) {
self.allClubs = playerz;
[self.tableView reloadData];
}
}];

但没有下载任何内容。

最佳答案

哟忘了调用 blockPlayers 完成处理程序。

- (void)getAllPlayers:(void (^)(NSArray *playerz, bool succeed))blockPlayers {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"https://api.myjson.com/bins/530re" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSarray *returnedPLayerz = [NSArray array];
//Here treat operation and response Object to extract playerz and assing it to returnedPlayerz
blockPLayers(returnedPlayerz, YES);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
blockPlayers(nil, NO);
NSLog(@"Error: %@", error);
}];

}

关于AFNetworking 的 iOS block 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31208700/

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