Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.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 presentViewController:动画:完成:导致我的程序崩溃_Ios_Objective C_Xcode_Ios7 - Fatal编程技术网

Ios presentViewController:动画:完成:导致我的程序崩溃

Ios presentViewController:动画:完成:导致我的程序崩溃,ios,objective-c,xcode,ios7,Ios,Objective C,Xcode,Ios7,我有一个RootViewController,它用实例方法presentViewController:animated:completion:呈现FirstViewController。我在方法中有一条日志消息(“呈现”);它的出现使我知道我的根目录正在FirstViewController中被调用,但由于某些原因,在程序崩溃之前,该消息会被连续记录 RootViewController -(void)presentViewController:(UIViewController *)viewC

我有一个RootViewController,它用实例方法presentViewController:animated:completion:呈现FirstViewController。我在方法中有一条日志消息(“呈现”);它的出现使我知道我的根目录正在FirstViewController中被调用,但由于某些原因,在程序崩溃之前,该消息会被连续记录

RootViewController

-(void)presentViewController:(UIViewController *)viewControllerToPresent
                  animated:(BOOL)flag
              completion:(void (^)(void))completion {

     NSLog(@"Presenting");

    [self presentViewController:viewControllerToPresent animated:flag completion:completion];
}
FirstViewController(我在其中调用该方法)


我不知道如何才能让这个方法只执行一次。这是我第一次使用该方法,但我假设消息只记录一次。

我想您想知道,何时调用了
presentViewController…
(编辑:…,因为其中只有日志调用和对同一方法的调用)。您可能还想调用super类方法,因此需要使用
super
而不是
self

-(void)presentViewController:(UIViewController *)viewControllerToPresent
                  animated:(BOOL)flag
              completion:(void (^)(void))completion {

     NSLog(@"Presenting");
    // Note super here:
    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
}

在原始代码中,您正在从内部调用相同的方法。这导致了许多日志消息。

难道
self
不应该呈现
root
?我以为root正在呈现self?就像RootViewController呈现我认为是self的FirstViewController一样。
-(void)presentViewController:(UIViewController *)viewControllerToPresent
                  animated:(BOOL)flag
              completion:(void (^)(void))completion {

     NSLog(@"Presenting");
    // Note super here:
    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
}