tabbedApliction

一、手动创建UITabBarController

  最常见的创建UITabBarController的地方就是在application delegate中的 applicationDidFinishLaunching:方法,因为UITabBarController通常是作为整个程序的rootViewController的,我们需要在程序的window显示之前就创建好它,具体步骤如下:

  1、创建一个UITabBarController对象

  2、创建tabbarcontroller中每一个tab对应的要显示的对象

  3、通过UITabBarController的viewController属性将要显示的所有content viewcontroller添加到UITabBarController中

  4、通过设置UITabBarController对象为window.rootViewController,然后显示window

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    
   SvTabBarFirstViewController *viewController1, *viewController2;

    viewController1 = [[SvTabBarFirstViewController alloc] initWithNibName:nil bundle:nil];
    viewController1.title = @"First";
    
    viewController2 = [[SvTabBarFirstViewController alloc] initWithNibName:nil bundle:nil];
    viewController2.title = @"Second";
    
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.delegate = self;
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

    [viewController1 release];
    [viewController2 release];
    
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    
    return YES;
}

二。属性

  

@property(nonatomic,copy) NSArray *viewControllers;//视图控制器的集合

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated;//控制视图控制器是否显示动画

 

@property(nonatomic,assign) UIViewController *selectedViewController;//选中的当前视图控制器

@property(nonatomic) NSUInteger selectedIndex;//当前控制器的索引

 

@property(nonatomic,readonly) UINavigationController *moreNavigationController;

UITabBar上最多可以显示5个Tab,当我们往UITabBarController中添加超过的viewController超过5个时候,最后一个一个就会自动变成,按照设置的viewControlles的顺序,显示前四个viewController的tabBarItem,后面的tabBarItem将不再显示。当点击more时候将会弹出一个标准的navigationViewController,里面放有其它未显示的的viewController,并且带有一个edit按钮,通过点击该按钮可以进入类似与ipod程序中设置tabBar的编辑界面。编辑界面中默认所有的viewController都是可以编辑的,我们可以通过设置UITabBarController的customizableViewControllers属性来指定viewControllers的一个子集,即只允许一部分viewController是可以放到tabBar中显示的。但是这块儿要注意一个问题就是每当UITabBarController的viewControllers属性发生变化的时候,customizableViewControllers就会自动设置成跟viewControllers一致,即默认的所有的viewController都是可以编辑的,如果我们要始终限制只是某一部分可编辑的话,记得在每次viewControlles发生改变的时候,重新设置一次customizableViewControllers。

@property(nonatomic,copy) NSArray *customizableViewControllers;

 

@property(nonatomic,readonly) UITabBar *tabBar NS_AVAILABLE_IOS(3_0);//UITabBar是最下面的导航    UITabBar自己有一些方法是可以改变自身状态,但是对于UITabBarController自带的tabBar,我们不能直接去修改其状态。任何直接修改tabBar的操作将会抛出异常,下面看一个抛出异常的小例子 

@property(nonatomic,assign) id<UITabBarControllerDelegate> delegate;委托

旋转 ;当所有的viewcontry都允许旋转UITabBarController才允许旋转

 三。继承 

四。声明周期
原文地址:https://www.cnblogs.com/flyingdreaming/p/tabbedApliction.html