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