afnetworking如何将回发数据发送到其他类

时间:2014-11-17 05:52:35

标签: ios objective-c afnetworking

这是我的代码。

-(void)aaaa{
[AFNetworkActivityIndicatorManager sharedManager].enabled=YES;
[[ClientAPI sharedClient] POST:@"api/expert/get-tests.php" parameters:nil success:^(NSURLSessionDataTask *task, id content){
    NSLog(@"nslogjson: %@%@",task.response,content );} 
failure:^(NSURLSessionDataTask *task,NSError *error){NSLog(@"%@",error);}];
[AFNetworkActivityIndicatorManager sharedManager].enabled=YES;
}

我不想要这些数据的NSlog。我想得到"内容"回到另一个班级。怎么办?

2 个答案:

答案 0 :(得分:1)

使用阻止的时间:

- (void)aaaaWitCompletion:(void (^)(id response)completionBLock {

[[ClientAPI sharedClient] POST:@"api/expert/get-tests.php" parameters:nil success:^(NSURLSessionDataTask *task, id content){
    NSLog(@"nslogjson: %@%@",task.response,content);
    if (completionBLock) {
    completionBLock(task.response);
    }
} 
failure:^(NSURLSessionDataTask *task,NSError *error){
    NSLog(@"%@",error);
    }];
}

//  Somewhere in your code:

- (void)updateButtonAction:(id)sender {

   [self aaaaWitCompletion:^(id response) {
//  Use your response here
   }];
}

答案 1 :(得分:-1)

class 2

@property(NSDictionary*) json;

class 1
//json
class2obj2=[[class2 alloc] init];
class2obj.json=json;
[self.navigationcontroller pushViewController:class2obj];