gpt4 book ai didi

ios - 如何将另一个 UIViewController 添加到现有的 UINavigationController

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:15:58 25 4
gpt4 key购买 nike

我有一个带有两个 View Controller 的应用程序。第一个嵌入在导航 Controller 中并有一个导航栏,在第一个 View Controller 中的某个方法结束后,我以编程方式呈现第二个 View Controller 。这工作正常,但这样第二个 View Controller 不是导航 Controller 堆栈的一部分,并且与第一个 View Controller 没有任何关系。像这样,我无法利用导航 Controller 。关于如何解决这个问题的任何想法?

在用户从照片库中选取图像后,我向第二个 View Controller 显示此代码:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
pickedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissViewControllerAnimated:YES completion:NULL];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController *viewController = (ViewController *)[storyboard instantiateViewControllerWithIdentifier:@"viewControllerID"];
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:viewController animated:YES completion:nil];
}

最佳答案

而不是

[self presentViewController:viewController animated:YES completion:nil];

使用

[self.navigationController pushViewController:viewController animated:YES];

这样VC2也在同一个导航栈中

您的最终代码如下所示:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController *viewController = (ViewController *)[storyboard instantiateViewControllerWithIdentifier:@"viewControllerID"];
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController pushViewController:viewController animated:YES];
}

关于ios - 如何将另一个 UIViewController 添加到现有的 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29921983/

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