zoukankan      html  css  js  c++  java
  • [Swift][OC]代码实现导航

    先看看效果,很简单的东西

    swift版:

    sb里建立这样的控制器

    别忘了设置storyboard ID

    分别设置三个button的tag为101,102,103

     @IBAction func BtnClick(sender: UIButton) {
            switch sender.tag {
            case 101:
                let redVC = storyboard?.instantiateViewControllerWithIdentifier("redVC")
                //先通过storyboard ID取得对应的ViewController
                self.navigationController?.pushViewController(redVC!, animated: true)
                //通过push方法压栈
            case 102:
                let orangeVC = storyboard?.instantiateViewControllerWithIdentifier("orangeVC")
                self.navigationController?.pushViewController(orangeVC!, animated: true)
            case 103:
                let blueVC = storyboard?.instantiateViewControllerWithIdentifier("blueVC")
                self.navigationController?.pushViewController(blueVC!, animated: true)
            default:
                break
            }
        }
    

     OC版:

    .h文件中定义一个UIViewController

    @property(nonatomic,assign)UIViewController *con;
    

     .m文件中

    - (IBAction)clicked:(UIButton *)sender {
        switch (sender.tag) {
            case 101:
                _con = [self.storyboard instantiateViewControllerWithIdentifier:@"redVC"];
                [self.navigationController pushViewController:_con animated:YES];
                break;
            case 102:
                _con = [self.storyboard instantiateViewControllerWithIdentifier:@"blueVC"];
                [self.navigationController pushViewController:_con animated:YES];
                break;
                
            default:
                break;
        }
    }
    

     思路都是一样的,其中一般每个ViewController都有对应的类,上面的通过storyboard id初始化一个VC的时候可以这样写

  • 相关阅读:
    汉字在屏幕上的显示
    手机上的ROM与RAM
    数据表示和计算
    存储器的层次结构
    计算机系统概述
    Python中的文件路径的分隔符
    网络爬虫的基本原理
    iOS多线程简介
    Quartz2D简介
    iOS 事件传递响应链
  • 原文地址:https://www.cnblogs.com/ybw123321/p/5417231.html
Copyright © 2011-2022 走看看