- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
MainView *Main=[[MainView alloc]initWithNibName:@"MainView" bundle:nil];
// This module to collect metrics for Notification received, Notification displayed
UINavigationController *NavBar=[[UINavigationController alloc] initWithRootViewController:Main];
// react to shortcut item selections
NSLog(@"A shortcut item was pressed. It was %@.", shortcutItem.localizedTitle);
if([(NSString *)shortcutItem.localizedTitle isEqualToString:@"Store"])
{
PurchaseView *purchaseViewController = [[PurchaseView alloc] initWithNibName:@"PurchaseView" bundle:nil];
[NavBar pushViewController:purchaseViewController animated:YES];
}
}
我输入 if([(NSString *)shortcutItem.localizedTitle isEqualToString:@" Store"])循环,我看到代码正在执行。但是PurchaseView.xib永远不会加载。我有推送通知的类似代码,它在我推送视图加载时有效。
任何帮助都将不胜感激。
答案 0 :(得分:2)
这里的问题是视图层次结构不好。您已将XIB
文件的视图控制器添加到视图层次结构中不存在的全新UINavigationController
。我相信你想做这样的事情:
UINavigationController *navBar = (UINavigationController *) self.tabBarController.selectedViewController;
[navBar pushViewController:purchaseViewController animated:YES];
同样,上面是一个假设的例子。您需要在视图层次结构中找到正确的UINavigationController
。