Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何获取变量';一个区块的价值是多少?_Ios_Objective C - Fatal编程技术网

Ios 如何获取变量';一个区块的价值是多少?

Ios 如何获取变量';一个区块的价值是多少?,ios,objective-c,Ios,Objective C,我实现了如下方法: -(void)startAnimating:(MyCompletion)performMethod { _displayViewForActivityIndicator = [[ProcessingIndicationView alloc] initWithFrame:CGRectMake(-self.view.frame.size.width, -self.view.frame.size.height, self.view.frame.size.width, self.vi

我实现了如下方法:

-(void)startAnimating:(MyCompletion)performMethod {
_displayViewForActivityIndicator = [[ProcessingIndicationView alloc] initWithFrame:CGRectMake(-self.view.frame.size.width, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:_displayViewForActivityIndicator];
LogDebug(@"Start the method");
[UIView animateWithDuration:1.5f
                      delay:0.0f
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     //end position:
                     _displayViewForActivityIndicator.frame = self.view.frame;
                 }
                 completion:^(BOOL finished)
 {
     performMethod();
 }];
}

我使用的方法如下:

  - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender: (id)sender
 {
 BOOL ret = NO;
 NSString *userId = [ViewsDataManager sharedManager].userID;
 LogDebug(@"userID = %@", userId);
 if ((userId!=nil)&&(![userId isEqualToString:@""])) {
    __block bool a = NO;
    [self startAnimating:^{
        a = [self deleteUserService];
        LogDebug(@"a1 = %d", a);
    }];
    LogDebug(@"a2 = %d", a);
    if (a) {
        [ViewsDataManager sharedManager].userID = nil;
        LogDebug(@"Delete user successfully");
        ret = YES;
    }
    else{
        ret = NO;
    }
}
LogDebug(@"ret == %d",ret);
return ret;
}


变量a在块中设置,我想在块外使用它的值。我该怎么做呢?

你的代码没有意义。动画运行后(异步!)将调用完成块,但在此之前您正在访问变量。您可能还希望将其放入完成块。

在块中,将
a
设置为您想要使用它的任何位置。此处的块是异步的;代码的其余部分可能在块完成和赋值之前完成。你不能在块内使用变量有什么原因吗?声明一个全局变量并在该块内使用该变量。不,不要使用全局变量。我想得到ret的值,它取决于一个变量,如果在块内设置ret=YES,最后设置ret variable=No。谢谢@DavidJirman