嗨,我的 plist 中有两个 3D 快速操作快捷方式项目。我将我的处理程序代码放在 App 委托中,如下所示:
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
if (storyboard==nil){
storyboard=[UIStoryboard storyboardWithName:@"Storyboard" bundle:[NSBundle mainBundle]];
}
ViewController *vc = [storyboard instantiateInitialViewController];
self.window.rootViewController = vc;
if([shortcutItem.type isEqualToString:@"firstItem"]){
[vc performSegueWithIdentifier:@"firstSegue" sender:self];
}else{
[vc handleSecondQuickAction];
}
}
基本上,有两种情况,一种是应用程序首次启动,另一种是应用程序已经在后台并从主屏幕启动。
我放了以下代码来检查故事板是否还活着,这样当应用程序已经启动时我就不会再次创建故事板:
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
if (storyboard==nil){
storyboard=[UIStoryboard storyboardWithName:@"Storyboard" bundle:[NSBundle mainBundle]];
}
我的问题在这里:
if([shortcutItem.type isEqualToString:@"firstItem"]){
[vc performSegueWithIdentifier:@"firstSegue" sender:self];
}
如果我多次执行快速操作“firstItem”(通过返回主屏幕并以快速操作重新启动),我会在内存中获得多个视图控制器,我认为这是内存泄漏。
我不确定我是否正确执行此操作,我不会从项目文件负责处理的代码中启动情节提要。然而,快速动作处理程序必须以编程方式完成。
快速启动故事板的最佳方式是什么?任何人都可以提供一个好的解决方案?谢谢!