如何从 UIView 导航 UIViewController [英] How to Navigate UIViewController from UIView
问题描述
我是 iOS 开发的新手,请给我一个从 UIView 导航到 UIViewController 的解决方案:这是我使用过的代码,但它不起作用
Hi I'm New to iOS Development and Please give me a solution to navigate to UIViewController from an UIView: This is the code I have used but it is not working
acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
[self.navigationController pushViewController:acceptedJobDetailViewController animated:YES];
我也尝试了下面的代码来推送视图控制器,但这也不起作用,请帮我解决这个问题:
Also i tried this below code to push the viewcontroller but that is also not working, Please help me to sort out this:
[appDelegate.navControl pushViewController:acceptedJobDetailViewController animated:YES];
推荐答案
如果您已经在 storyboard
中添加了 NavigationController
并且您正在尝试从 推送屏幕>UIView
类比使用下面的代码:
If you have already added NavigationController
in your storyboard
and you are trying to push screen from UIView
Class than use below code :
UIViewController *superViewController = (UIViewController*)[self nextResponder];
UINavigationController *navigationController = superViewController.navigationController;
[navigationController pushViewController:<YOUR_VIEW_CONTROLLER_OBJECT> animated:YES];
如果你还没有和任何导航,请将它添加到你的 ViewController 之前,如下所示
if you haven't and any navigation please add it before your ViewController like below
Select ViewController -> Go to Editor Menu -> Embed In -> Navigation Controller
现在将导航控制器添加到您的故事板中,现在可以执行您之前所做的操作.
Now Navigation Controller added into your storyboard now do what you are doing previously.
acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
[self.navigationController pushViewController:acceptedJobDetailViewController animated:YES];
希望这会有所帮助.
这篇关于如何从 UIView 导航 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!