如何获取“当前”标签栏控制器的导航控制器
有没有一种方法可以检索选项卡栏控制器当前的可见导航控制器?
例如,我的程序中有 2 个选项卡栏(每个选项卡一个导航控制器),如下所示
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//Method is called when user clicks on a hyperlink in one of view controllers
NSDictionary *dict = [self parseQueryString:[url query]];
NSString *userID = [dict objectForKey:@"id"];
NSString *navconTitle = [dict objectForKey:@"navcon"];
//intention is to push a view controller onto the CURRENT navigation stack
[navcon pushViewController:someViewController animated:YES];
}
}
return YES;
}
任何人都可以告诉我如何确定当前的导航控制器,以便我可以将更多的视图控制器推送到它上面?
Is there is a method to retrieve tab bar controller's current visible navigation controller?
For example, I have 2 tabbars in my program (one navigation controller each) as below
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//Method is called when user clicks on a hyperlink in one of view controllers
NSDictionary *dict = [self parseQueryString:[url query]];
NSString *userID = [dict objectForKey:@"id"];
NSString *navconTitle = [dict objectForKey:@"navcon"];
//intention is to push a view controller onto the CURRENT navigation stack
[navcon pushViewController:someViewController animated:YES];
}
}
return YES;
}
Can anyone advise me how I can determine the current navigation controller so that I can push more viewcontrollers onto it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
UITabBarController
selectedViewController 属性。Use the
UITabBarController
s selectedViewController property.更新 Starsky 对 iOS 13 的 Swift 答案(“'keyWindow' 在 iOS 13.0 中已弃用”)
Updating Starsky's Swift answer to iOS 13 ("'keyWindow' was deprecated in iOS 13.0")
我认为
UITabBarController selectedViewController
属性应该是您正在寻找的。因此,从 UITabBarController 方法:-
I think
UITabBarController selectedViewController
property should be what you are looking for.So, from a UITabBarController method :-
一个 Swift 版本,以防有人无法阅读 Objective-C,并提供了如何从任何地方找到 tabBar 的附加解决方案。我在处理通知时用它来推送到屏幕。
A Swift version, in case someone can't read Objective-C, with an additional solution for how to find the tabBar from anywhere. I use this to push to a screen when processing a notification.