您好我的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];
}
如果我做quickAction" firstItem"多次(通过返回主屏幕并快速重新启动)我在内存中获得了多个视图控制器,我认为这是内存泄漏。
我不确定我是否正确地执行此操作,我不会从项目文件处理的代码启动故事板。但是,必须以编程方式完成快速操作处理程序。
快速操作启动故事板的最佳方式是什么?谁能提供一个好的解决方案?谢谢!