Ios 在目标c中使用完成块完成一种方法后,如何执行另一种方法?

Ios 在目标c中使用完成块完成一种方法后,如何执行另一种方法?,ios,objective-c,completion-block,Ios,Objective C,Completion Block,我有两种方法。我想在完成第一个任务后再执行一个。我该怎么做 你可以这样做 [[manager POST:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { NSLog(@"This is success!!!"); //this is first method's completion bl

我有两种方法。我想在完成第一个任务后再执行一个。我该怎么做

你可以这样做

    [[manager POST:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {

            NSLog(@"This is success!!!");

       //this is first method's completion blcok!

               // this is another method from completion of first
                    [self saveImages:^(BOOL isDone) {

                        // this is second method's completion

                    }];

               } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            NSLog(@"failure : Error is : %@",error.localizedDescription);

          // this is completion of first method but with failure

        }]resume];

这是如何管理它的简单示例!!在这里,我使用了这个方法,所以不要混淆它

我假设您正在寻找简单的完成块解决方案,因此这应该足够了

-(void)method1:(void (^ __nullable)(void))completion {
    NSLog(@"method1 started");
    //Do some stuff, then completion
    completion();
    NSLog(@"method1 ended");
}
-(void)method2{
    NSLog(@"method2 called");
}
像这样使用,

- (void)viewDidLoad{
    [super viewDidLoad];
    [self method1:^{   //After method1 completion, method2 will be called
        [self method2];
    }];
}

在返回第一个方法完成之前,将一些代码放入第二个方法行handler@SivajeeBattina请给我看一些代码,我在completion handler.func doSomething(flag:Bool,completionHandler:(success:Bool)->Void){//这里需要调用第二个方法self.secondMethod()completionHandler(success:true)}func secondMethod(){}