我正在构建一个静态库,为不同的应用程序提供UI内容,每当我动态设置app delegate的窗口rootviewcontroller时,我需要知道如何恢复它而不会丢失所有显示的视图控制器。我们说我有这个代码
@interface SampleViewController : UIViewController{
UIViewController *_originalRootViewController;
}
...
-(IBAction)openSomething:(id)sender{
UIWindow * window = [[UIApplication sharedApplication] delegate] window];
_originalRootViewController = window.rootViewController;
window.rootViewController = self;
}
-(IBAction)closeSomething:(id)sender{
UIWindow * window = [[UIApplication sharedApplication] delegate] window];
//PROBLEM, doing this shows the first view of the app instead of the latest view controller that was pushed on the view hierarchy
window.rootViewController = _originalRootViewController;
}
有关如何解决此问题的任何建议?在我提出另外一个关于使用2个UIWindows的问题之前,其他人告诉我只使用1个UIWindow,尽管我告诉他因为这个问题不可能。