gpt4 book ai didi

ios - 如何向推送另一个 View Controller 的 UINavigationController 添加右键?

转载 作者:行者123 更新时间:2023-11-29 12:46:50 26 4
gpt4 key购买 nike

我有一个连接到导航 Controller 的 View Controller 。我想在顶部的导航栏中添加一个右键,以插入另一个 View Controller 。如果我添加右键:

UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonItemStylePlain target:self action:[self forward]];
self.navigationItem.rightBarButtonItem = Button;

按钮出现。但是,如果我将以下行添加到 forward 方法中,按钮将再次消失:

MapViewController *viewController = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"map"];
[self.navigationController pushViewController:viewController animated:YES];

正确的做法是什么?

最佳答案

在您的代码中声明 UIBarButtonItemaction:[self forward]] 行有问题...将其更改为 @selector(forward ) 或者试试这个

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(showNextVC)];          
self.navigationItem.rightBarButtonItem = nextButton;

showNextVC 中:

-(void) showNextVC {
MapViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"map"];
[self.navigationController pushViewController:viewController animated:YES];
}

关于ios - 如何向推送另一个 View Controller 的 UINavigationController 添加右键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23487657/

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