zoukankan      html  css  js  c++  java
  • 控制器的切换(button不在导航栏上)

    首先上效果图:

    然后上代码:

    创建几个用于切换的控制器,分别命名AviewController,BviewController,CviewController,DviewController

    创建一个ViewController,在viewController.m中写以下代码就可以轻松实现控制器的切换了

    #import "ViewController.h"

    #import "AViewController.h"

    #import "BViewController.h"

    #import "CViewController.h"

    #import "DViewController.h"

    @interface ViewController ()

    @property(nonatomic,strong)AViewController *aVC;

    @property(nonatomic,strong)BViewController *bVC;

    @property(nonatomic,strong)CViewController *cVC;

    @property(nonatomic,strong)DViewController *dVC;

     @end

    @implementation ViewController

    - (AViewController *)aVC

    {

        if (!_aVC) {

            self.aVC = [[AViewController alloc] init];

            self.aVC.view.frame = CGRectMake(0, 110, self.view.frame.size.width, self.view.frame.size.height-110);

        }

        return _aVC;

    }

    - (BViewController *)bVC

    {

        if (!_bVC) {

            self.bVC = [[BViewController alloc] init];

            self.bVC.view.frame =CGRectMake(0, 110, self.view.frame.size.width, self.view.frame.size.height-110);;

        }

        return _bVC;

    }

      

    - (CViewController *)cVC

    {

        if (!_cVC) {

            self.cVC = [[CViewController alloc] init];

            self.cVC.view.frame = CGRectMake(0, 110, self.view.frame.size.width, self.view.frame.size.height-110);

        }

        return _cVC;

    }

    - (DViewController *)dVC

    {

        if (!_dVC) {

            self.dVC = [[DViewController alloc] init];

            self.dVC.view.frame =CGRectMake(0, 110, self.view.frame.size.width, self.view.frame.size.height-110);

        }

        return _dVC;

    }

    - (IBAction)didClickA:(id)sender {  

        [self.bVC.view removeFromSuperview];

        [self.cVC.view removeFromSuperview];

        [self.dVC.view removeFromSuperview];

        [self.view addSubview:self.aVC.view];   

    }

    - (IBAction)didClickB:(id)sender {

        [self.aVC.view removeFromSuperview];

        [self.cVC.view removeFromSuperview];

        [self.dVC.view removeFromSuperview];

        [self.view addSubview:self.bVC.view];

    }

    - (IBAction)didClickC:(id)sender {

        [self.aVC.view removeFromSuperview];

        [self.bVC.view removeFromSuperview];

        [self.dVC.view removeFromSuperview];

        [self.view addSubview:self.cVC.view];

     }

    - (IBAction)didClickD:(id)sender {

        [self.bVC.view removeFromSuperview];

        [self.cVC.view removeFromSuperview];

        [self.aVC.view removeFromSuperview];

        [self.view addSubview:self.dVC.view]; 

    }

    一个人,一片天,一条路,一瞬间!
  • 相关阅读:
    JavaWeb网上图书商城完整项目--day02-3.regist页面输入框失去焦点进行校验
    JavaWeb网上图书商城完整项目--day02-2.regist页面输入框得到焦点隐藏label
    JavaWeb网上图书商城完整项目--27.注册页面之注册按钮图片切换实现
    关于js中值的比较规则问题
    说说null和undefined的那些事
    对象、数组转换字符串
    函数的形参与实参
    switch判断注意点
    删除数组值
    数组的一个强大函数splice,[增,删,改]
  • 原文地址:https://www.cnblogs.com/zcl410/p/4888408.html
Copyright © 2011-2022 走看看