分栏控制器与导航控制器的联合使用-主流框架

现在的一些主流的框架基本上是按 分栏控制器和导航控制器配合使用的

导航控制器负责横向切换

分栏控制器是控制纵向的切换

我们应该研究 一些主流框架的实现原理 在此基础上提升的速度才会比较快

这里只是给大家抛砖,希望大家能够学习到一些知识

我们所说的栈控制器 -本质上就是一个数组 ,用于管理每个页面

直接上代码了:

//
//  AppDelegate.h
//  88888-tabbar

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
//
//  AppDelegate.m
//  88888-tabbar

#import "AppDelegate.h"
#import "GPoneController.h"
#import "GPTwoController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    UITabBarController *tab = [[UITabBarController alloc]init];

    GPoneController *one = [[GPoneController alloc]init];
    one.view.backgroundColor = [UIColor blueColor];

    UINavigationController *nvcOne = [[UINavigationController alloc]initWithRootViewController:one];
    nvcOne.tabBarItem.title = @"你的";

    GPTwoController *two = [[GPTwoController alloc]init];
    two.view.backgroundColor = [UIColor greenColor];

    UINavigationController *nvcTwo = [[UINavigationController alloc]initWithRootViewController:two];

    nvcTwo.tabBarItem.title = @"我的";

    NSArray *controllers = @[nvcOne,nvcTwo];

    tab.viewControllers = controllers;

    self.window.rootViewController = tab;

    [self.window makeKeyAndVisible];
    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
//
//  GPoneController.h
//  88888-tabbar

#import <UIKit/UIKit.h>

@interface GPoneController : UIViewController

@end
//
//  GPoneController.m
//  88888-tabbar

#import "GPoneController.h"
#import "GPBookListController.h"

@interface GPoneController ()

@end

@implementation GPoneController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 100, 200, 30);
    [btn setTitle:@"我的书库" forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(btnTouch) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

    // Do any additional setup after loading the view.
}
-(void)btnTouch
{
    GPBookListController *book = [[GPBookListController alloc]init];
    book.view.backgroundColor = [UIColor grayColor];

    [self.navigationController pushViewController:book animated:YES];
    NSLog(@"btnTouch");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
//
//  GPTwoController.h
//  88888-tabbar

#import <UIKit/UIKit.h>

@interface GPTwoController : UIViewController

@end
//
//  GPTwoController.m
//  88888-tabbar

#import "GPTwoController.h"

@interface GPTwoController ()

@end

@implementation GPTwoController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

//

//  GPBookListController.h

//  88888-tabbar

#import <UIKit/UIKit.h>

@interface GPBookListController :
UIViewController

@end

//
//  GPBookListController.m
//  88888-tabbar

#import "GPBookListController.h"
#import "GPnextController.h"

@interface GPBookListController ()

@end

@implementation GPBookListController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 200, 100, 30);
    [btn setTitle:@"跳转到你的页面" forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(btnTouch) forControlEvents:UIControlEventTouchUpInside];

    // Do any additional setup after loading the view.
}

-(void)btnTouch
{
    GPnextController *nvc = [[GPnextController alloc]init];

    [self.navigationController pushViewController:nvc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
//
//  GPnextController.h
//  88888-tabbar
//

#import <UIKit/UIKit.h>

@interface GPnextController : UIViewController

@end
//
//  GPnextController.m
//  88888-tabbar

#import "GPnextController.h"

@interface GPnextController ()

@end

@implementation GPnextController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor purpleColor];

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    btn.frame = CGRectMake(0,200, 200, 30);

    [btn setTitle:@"设置个人信息" forState:UIControlStateNormal];

    btn.backgroundColor = [UIColor cyanColor];

    [self.view addSubview:btn];

    [btn addTarget:self action:@selector(btnTouch) forControlEvents:UIControlEventTouchUpInside];

    // Do any additional setup after loading the view.
}

-(void)btnTouch
{
    NSLog(@"设置成功");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-08 19:55:47

分栏控制器与导航控制器的联合使用-主流框架的相关文章

02---按钮的设置 控制器拥有导航栏包装一层导航控制器 添加子控制器 UIBarButtonItem导航按钮 设置导航栏UINavigationBar主题 设置状态栏样式

一.按钮的设置 1.设置背景图片 [btn setBackgroundImage:image forState:UIControlStateNormal]; 2.内部UIImageView 1> 设置内部UIImageView的图片 [btn setImage:image forState:UIControlStateNormal]; // 不能写成btn.imageView.image = image; 2> 调整内部图片的内容模式 self.imageView.contentMode =

多控制器和导航控制器简单介绍

一.多控制器 一个iOS的app很少只由一个控制器组成,除非这个app极其简单.当app中有多个控制器的时候,我们就需要对这些控制器进行管理 有多个view时,可以用一个大的view去管理1个或者多个小view,控制器也是如此,用1个控制器去管理其他多个控制器 比如,用一个控制器A去管理3个控制器B.C.D.控制器A被称为控制器B.C.D的“父控制器”:控制器B.C.D的被称为控制器A的“子控制器” 为了便于管理控制器,iOS提供了2个比较特殊的控制器 UINavigationControlle

iOS开发UI篇—多控制器和导航控制器简单介绍

iOS开发UI篇—多控制器和导航控制器简单介绍 一.多控制器 一个iOS的app很少只由一个控制器组成,除非这个app极其简单.当app中有多个控制器的时候,我们就需要对这些控制器进行管理 有多个view时,可以用一个大的view去管理1个或者多个小view,控制器也是如此,用1个控制器去管理其他多个控制器 比如,用一个控制器A去管理3个控制器B.C.D.控制器A被称为控制器B.C.D的“父控制器”:控制器B.C.D的被称为控制器A的“子控制器” 为了便于管理控制器,iOS提供了2个比较特殊的控

iOS开发-21UINavigationController导航控制器初始化 导航控制器栈的push和pop跳转理解

(1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最下面,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界面,也就是用户看到的界面. (2)我们需要把导航控制器加载到APP中,需要把这个导航控制器设置为window的根视图控制器(都是控制器类,可以赋值),这样就相当于加载到了window里. (3)我们要在栈中新增或者删除一个视图控制器,就需要得到导航控制器,一般在栈中得所有视图控制器都有一个self.

导航栏控制器和标签栏控制器(UINavigationController和UITabBarController)混用

很多时候,在UI设计方面同时需要使用导航控制器和标签栏控制器,这时,需要掌握如何设计结合使用这两种不同控制器.比如手机QQ,程序有三个标签栏(分别为消息.联系人.动态),同时在选择某个联系人或者会话时,会进入聊天的子页面,因此这里同时使用到了标签栏控制器和导航控制器. 我目前所知道有以下方法可实现上述的结合使用效果. 根视图是标签栏控制器,然后每页标签栏又有一个根视图控制器为导航栏控制器的标签,如下代码所示 // 消息 MessageViewController* msg = [[Message

UINavigationController 导航控制器

初始方法: - (id)initWithRootViewControl:(UIViewController *)rootViewController //初始化时,传递一个视图控制器的参数,作为导航控制器的根视图控制器,导航控制器实例加载完成后,根视图控制器的视图会被添加到导航控制器中 入栈操作: //从导航控制器某一个视图里面把另一个视图Push进导航控制器栈中. [self.navigationController pushViewController:(UIViewController *

IOS笔记046-UIApplication/导航控制器

阅读目录 UIApplication info.plist文件 pch文件 AppDelegate main.m文件 UINavigation - 导航控制器 storyboard实现控制器之间的跳转 回到顶部 UIApplication 每一个应用都有自己的UIApplication对象,而且是单例的 通过[UIApplication sharedApplication]可以获得这个单例对象 一个iOS程序启动后创建的第一个对象就是UIApplication对象 单例对象的获取 UIAppli

iOS开发UI篇—导航控制器属性和基本使用

IOS开发UI篇—导航控制器属性和基本使用 一.导航控制器的一些属性和基本使用 1.把子控制器添加到导航控制器中的四种方法 (1) 1.创建一个导航控制器 UINavigationController *nav=[[UINavigationControlleralloc]init]; 2.设置导航控制器为window的根视图 self.window.rootViewController=nav; 3.添加 YYOneViewController  *one = [[YYOneViewContro

UIKit框架(11)导航控制器UINavigationController

介绍多控制器管理中非常重要的一个控制器UINavigationController 它负责管理多个控制器,能够轻松完成控制器间的切换 如:iOS系统上的设置 父类是UIViewController,但其功能并非是管理view,而是管理多个控制器 控制器栈式管理: 当切换时,将一个控制器入栈,当返回时,栈顶控制器出栈 当前显示的永远是栈顶控制器的view,栈结构如下: @property(nonatomic, copy) NSArray *viewControllers  //管理的所有控制器