gpt4 book ai didi

swift - 当我选择选择器时如何显示另一个(更改)ViewController

转载 作者:行者123 更新时间:2023-11-30 14:19:05 25 4
gpt4 key购买 nike

当我选择选择器时,如何显示另一个(更改)ViewController。

我有一个选择器(简单、中级、困难),当我选择一个选择器并单击一个按钮时,我想转到特定的 View Controller (我有 3 个 View Controller (一个用于简单,一个用于中间)另一个是困难的)请帮助我

最佳答案

单击按钮时,您可以呈现或推送 View Controller 。如果您已将其与 segue 连接,您可以执行以下操作:

if(easySelected)
[self performSegueWithIdentifier:@"easyOne" sender:self];
else if
...

如果您有导航 Controller 或想要展示它,您可以这样做:

UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
EasyViewConroller *cont = [story instantiateInitialViewController];
// or EasyViewConroller *cont = [story instantiateViewControllerWithIdentifier:@"YourIdent"];
// in former solution you have to set that identifier in the code/storyboard

// navigation/push
self.navigationController pushViewController:cont animated:YES];

// if you want to present it
[self presentViewController:cont animated:YES completion:nil];

编辑:

if(easySelected){
self.performSegueWithIdentifier("easyOne" sender:self)
{
else if{
...
}

//If you have navigation controller or want to present it you can do:
var tempStory = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
var tempVC = tempStory.instantiateInitialViewController() as! EasyViewController

//present
self.presentViewController(tempVC, animated: true)

//push
self.navigationController?.pushViewController(tempVC, animated: true)

关于swift - 当我选择选择器时如何显示另一个(更改)ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30710431/

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