gpt4 book ai didi

ios - 如何从 UIView 导航 UIViewController

转载 作者:行者123 更新时间:2023-11-28 21:14:18 27 4
gpt4 key购买 nike

您好,我是 iOS 开发新手,请给我一个从 UIView 导航到 UIViewController 的解决方案:这是我使用过的代码,但它不起作用

acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
[self.navigationController pushViewController:acceptedJobDetailViewController animated:YES];

我还尝试了下面的代码来推送 View Controller ,但这也不起作用,请帮我解决这个问题:

[appDelegate.navControl pushViewController:acceptedJobDetailViewController animated:YES];

最佳答案

如果您已经在 storyboard 中添加了 NavigationController 并且您正尝试从 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

现在 Navigation Controller 添加到您的 Storyboard中,现在可以执行您之前正在执行的操作。

acceptedJobDetailViewController *acceptedJobDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"acceptedJobDetailViewController"];
[self.navigationController pushViewController:acceptedJobDetailViewController animated:YES];

希望这会有所帮助。

关于ios - 如何从 UIView 导航 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41849425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com