您需要让您的 UI 处于已知的就绪状态,因为不知道呼叫进入时它会在哪里。要做好准备,您需要有一个标签栏的句柄,并且能够转换将 URL 上的 uniqueid 插入到详细 vc 应该检查的模型部分。
它应该看起来像这样(对您现有的代码进行自由猜测):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// get the ui to a known state
self.tabBarController.selectedIndex = kTHE_NAVIGATION_VC_INDEX;
UINavigationController *nav = (UINavigationController *)self.tabBarController.selectedViewController;
[nav popToRootViewControllerAnimated:NO];
// parse the url to get uniqueId
// the uniqueId specifies an object in your model that you want to have
// inspected by the detail view controller? you'll need that object...
MyObject *detailObject = [self.myModel objectWithUniqueId:uniqueId];
// the detail vc probably has an init like this?
DetailVC *detailVC = [[DetailVC alloc] initWithModel:detailObject];
[nav pushViewController:detailVC animated:YES];
}
编辑
要让您的应用程序委托访问它的 tabBarController,您可以设置如下属性:
// AppDelegate.h
@property (strong, nonatomic) UITabBarController *tabBarController;
// AppDelegate.m, after @implementation
@synthesize tabBarController=_tabBarController;
您是否使用故事板 segue 从启动 vc 到主应用程序?我猜是的。从启动视图控制器到主应用程序是否有不止一个 segue?我猜NO。如果这些猜测中的任何一个是错误的,您将需要调整此代码...
// SplashViewController.m
#import "AppDelegate.h"
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UITabBarController *tabBarController = (UITabBarController *)[segue destinationViewController];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.tabBarController = tabBarController;
}