您好我是iOS开发的新手,请给我一个从UIView导航到UIViewController的解决方案:这是我使用的代码,但它无法正常工作
acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
[self.navigationController pushViewController:acceptedJobDetailViewController animated:YES];
此外,我尝试了以下代码来推送viewcontroller,但这也无法正常工作,请帮我理清:
[appDelegate.navControl pushViewController:acceptedJobDetailViewController animated:YES];
答案 0 :(得分:1)
请在故事板中添加导航控制器。
step -1: select acceptedJobDetailViewController from storyboard.
step -2: now go to Editor>EmbedIn>NavigationController
step -3: now below code and run your project
acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
答案 1 :(得分:1)
如果您已在NavigationController
中添加了storyboard
,并且您尝试从UIView
类推送屏幕而不是使用以下代码:
UIViewController *superViewController = (UIViewController*)[self nextResponder];
UINavigationController *navigationController = superViewController.navigationController;
[navigationController pushViewController:<YOUR_VIEW_CONTROLLER_OBJECT> animated:YES];
如果您还没有导航,请在ViewController之前添加,如下所示
Select ViewController -> Go to Editor Menu -> Embed In -> Navigation Controller
现在,导航控制器已添加到您的故事板中,现在可以执行您之前正在执行的操作。
acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
[self.navigationController pushViewController:acceptedJobDetailViewController animated:YES];
希望这会有所帮助。
答案 2 :(得分:0)
试试这个
[[(UIViewController *)[self.superview nextResponder] navigationController] pushViewController:"your viewcontroller object" animated:NO];
已更新为 swift 3
(superview?.next? as? UIViewController)?.navigationController?.pushViewController("your viewcontroller object", animated: false)