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]; 

    }

    一个人,一片天,一条路,一瞬间!
  • 相关阅读:
    bzoj:1299: [LLH邀请赛]巧克力棒
    [51nod][cf468D]1558 树中的配对
    HDU5447 Good Numbers
    Timus Online Judge:ural:1006. Square Frames
    poj1830:开关问题
    bzoj:1776: [Usaco2010 Hol]cowpol 奶牛政坛
    bzoj:1725: [Usaco2006 Nov]Corn Fields牧场的安排
    bzoj:1828: [Usaco2010 Mar]balloc 农场分配
    bzoj:1584: [Usaco2009 Mar]Cleaning Up 打扫卫生
    bzoj:1598: [Usaco2008 Mar]牛跑步
  • 原文地址:https://www.cnblogs.com/zcl410/p/4888408.html
Copyright © 2011-2022 走看看