IOS开发 分栏控制器高级

本节学习内容:

1.分栏控件器的代理使用

2.分校控制器的协义方法

3.分栏控制器的高级使用

分栏控制器高级协义函数

willBeginCustomizingViewcontrollers:即将显示编辑方法

willEndCustomizingViewControllers:妈将结束编辑方法

didEndCustonmizingViewControllers:已经结束编辑方法

didSelectViewController:选中控制器切换方法


创建6个视图控器,分别为VCFirst,VCSecond,VCThird,VCFour,VCFive,VCSix都继承于UIViewController


【AppDelegate.h】

#import<UIKit/UIKit.h>

@interface

//添加UITabBarController代理  UITabBarControllerDelegate

AppDelegate:UIResponder<UIApplicationDelegate,UITabBarControllerDelegate>

@property(strong,nonatomic)UIWindow *window;

@end

【AppDelegate.m】

#import "AppDelegate.h"

#import"VCFirst.h"

#import"VCSecond.h"

#import"VCThird.h"

#import"VCFour.h"

#import"VCFive.h"

#import"VCSix.h"

@interface AppDelegate()

@end

@implementation AppDelegate

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

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

[self.window makeKeyAndVisible];

VCFirst* vc01=[[VCFirst alloc]init];

VCSecond* vc02=[[VCSecond alloc]init];

VCThird* vc03=[[VCThird alloc]init];

VCFour* vc04=[[VCFour alloc]init];

VCSix* vc06=[[VCSix alloc]init];

vc01.view.backgroundColor=[UIColor blueColor];

vc02.view.backgroundColor=[UIColor YellowColor];

vc03.view.backgroundColor=[UIColor purpleColor];

vc04.view.backgroundColor=[UIColor grayColor];

vc05.view.backgroundColor=[UIColor greenColor];

vc06.view.backgroundColor=[UIColor orangeColor];

vc01.title="视图1";

vc02.title="视图2";

vc03.title="视图3";

vc04.title="视图4";

vc05.title="视图5";

vc06.title="视图6";

//创建数据

NSArray* arrayVC=[NSArray arrayWithObjects:VC01,vc02,vc03,vc04,vc05,vc06,nil];

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

tbc.viewController=arrayVC;

tbc.tabBar.translucent=NO;

self.window.rootViewController=tbc;

//改变工具栏颜色

tbc.tabBar.barTintColor=[UIColor redColor];

//更改按钮风格颜色

tbc.tabBar.tintColor=[UIColor blackColor];

//添加代理

tbc.delegate=self;

return YES;

}

//开始编辑前调用

-(void)tabBarController:(UITabBarController *)tabBarController willBeginCustonizingViewControllers:(NSArray<_kindof UIViewController *> *)viewControllers{

NSLog(@"编辑器前");

}

-(void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray<_kindof UIViewController *>*)viewControllers changed:(BOOL)changed{

NSLog("即将结束前");

}

-(void)tabBarController:(UITabBarController *)tabBarController didEndCustonizingViewContollers:(NSArray<_kindof UIViewController *>>*)viewControllers changed:(BOOL)changed{

NSLog(@"VCS=%@,viewControllers");

if(changed==YES){

NSLog(@"顺序发生改变!");

}

NSLog(@"已经结束编辑!");

}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

//选中的制器的索引与传入的索引是否一样

if(tabBarController.viewControllers[tabBarController.selectedInded]==viewController){

NSLog(@"OK");

}

NSLog(@"选 中控制器对象");

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,586评论 1 14
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 861评论 0 0
  • 分栏控制器的概念: 分栏控制器是管理多个视图控制器的管理控制器,通过数组的方式管理多个平行关系的视图控制器,与...
    奔跑的小小鱼阅读 528评论 0 0
  • 《我眼中的时间管理》 先举几个栗子。 1.榜样某用户:“大一学生 自制力欠缺 每天都过得好散漫 不想再酱紫了Σ(っ...
    启瀚Sir阅读 280评论 0 0
  • 今天刚交完接下来6、7、8三个月的房租和水电费,带来上海的生存本金所剩无几,大概真的和弟弟心有灵犀一点通...
    梨子李子栗子Liz阅读 311评论 0 1