Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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 如何在向后导航中获取视图控制器情节提要id或RestorationIdentifier?_Ios_Objective C_Xcode_Uiviewcontroller - Fatal编程技术网

Ios 如何在向后导航中获取视图控制器情节提要id或RestorationIdentifier?

Ios 如何在向后导航中获取视图控制器情节提要id或RestorationIdentifier?,ios,objective-c,xcode,uiviewcontroller,Ios,Objective C,Xcode,Uiviewcontroller,在我的导航中,我有一个rootViewController(AController)、第二个ViewController(BController)和第三个ViewController(CController)。 我可以通过按-->B-->C来导航我的应用程序 当我从C-->B返回时,在B控制器:viewdidLoad中,我如何从C导航而不是从A导航 我尝试使用self.presentedViewController.restorationIdentifier,但它总是返回控制器的标识符,而不是控

在我的导航中,我有一个rootViewController(AController)、第二个ViewController(BController)和第三个ViewController(CController)。 我可以通过按-->B-->C来导航我的应用程序

当我从C-->B返回时,在
B控制器:viewdidLoad
中,我如何从C导航而不是从A导航

我尝试使用self.presentedViewController.restorationIdentifier,但它总是返回控制器的标识符,而不是控制器的标识符

我应该使用storyboardID属性吗?我该怎么做


非常感谢您的帮助。

此类应用的最佳实践是使用
UINavigationController
进行导航。如果您使用的是
UINavigationController
导航,那么viewDidLoad只会在从A转到B时被调用,而在从C回到B控制器时不会被调用尝试在加载C并再次返回B时使用委派在B中设置属性。
此外,正如@khawar ali所提到的,
viewDidLoad
仅在首次加载视图控制器时才会被调用,因此从C返回时不会调用
viewDidLoad
方法。请尝试
viewwillbeen
/
viewdidbeen
:/

同意。以下是UIViewController生命周期的图像,以帮助您理解。我需要在
(void)viewdide:(BOOL)animated
事件结束中获取此信息。。。甚至在我的向后导航中也会出现这种情况……一种方法是在appdelegate类中使用NSString,并在每个控制器的ViewDidAspect函数中使用所需的a、B或C值更新NSString。然后,您可以访问上次调用的类:A或C,当您在ViewDidDisplay中访问它时。但在AppDelegates中使用全局变量不是一个好的做法,因此您可以选择使用
NSUserDefaults
为此感谢您,Khawar,我使用了您关于NSUserDefaults的建议!