【问题标题】:How I can display another (change) ViewController when I select a picker选择选择器时如何显示另一个(更改)ViewController
【发布时间】:2015-06-08 13:28:44
【问题描述】:

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

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

【问题讨论】:

    标签: swift button viewcontroller picker


    【解决方案1】:

    单击按钮时,您可以呈现或推送视图控制器。如果您已将其与 segue 连接,则可以执行以下操作:

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

    如果你有导航控制器或想要展示它,你可以这样做:

    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)
    

    【讨论】:

    • 好的,给我 10 分钟
    • 对不起,如果你给了我两种可能性,我没有理解?
    • 三个选项:segue、present 和 push to navigation controller
    猜你喜欢
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多