Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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 在objective c中使用UIAlertViewController时,如何取消显示的视图控制器?_Ios_Objective C_Swift_Xcode_Uialertviewcontroller - Fatal编程技术网

Ios 在objective c中使用UIAlertViewController时,如何取消显示的视图控制器?

Ios 在objective c中使用UIAlertViewController时,如何取消显示的视图控制器?,ios,objective-c,swift,xcode,uialertviewcontroller,Ios,Objective C,Swift,Xcode,Uialertviewcontroller,我没有使用任何使用导航控制器来显示视图控制器。在该视图控制器中,我使用NSTimer在特定时间后关闭视图控制器。我还使用AlertViewController显示时间已过的警报。但在这段时间之后,只有AlertViewController会解除实际的视图控制器。代码如下: -(void) callAfterSixtySecond:(NSTimer*) t { UIAlertController *alert = [UIAlertController alertController

我没有使用任何使用导航控制器来显示视图控制器。在该视图控制器中,我使用NSTimer在特定时间后关闭视图控制器。我还使用AlertViewController显示时间已过的警报。但在这段时间之后,只有AlertViewController会解除实际的视图控制器。代码如下:

    -(void) callAfterSixtySecond:(NSTimer*) t
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Running Time Loop" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            //button click event
                        }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:cancel];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
    [self stopReading];  ***************** **Executing this function**
    [self sendResult:@"Timeout"];
    NSLog(@"red");
}
在特定时间后执行的功能是:

-(void)stopReading{
  [self dismissViewControllerAnimated:YES completion:nil];
}
当我使用presentViewController显示警报时。因此,如果使用self.dismissViewController,它只会解除警报,而不是父视图控制器。那么,如何取消父视图控制器呢?注意:我没有使用任何导航控制器。

A)只需使用代码,我就可以关闭显示视图控制器:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

B) 或者另一种替代方法可以是,首先我们关闭视图控制器,然后在完成处理程序中,我们可以显示UIAlertViewController。

@matt感谢您的回复,但我可以使用[self.presentingViewController DismissViewController激活:是完成:否];相反?@马特,你能确认一下吗?