IOS_17 _ controller switchover _ TabBarController _ loading storyboard in ios Mode
Finally:
Main. storyboard
BeyondViewController. m contains a key code to set the style of the tabbarItem image (30*30)
//// BeyondViewController. m // 17 _ controller switch 2_tabbarController // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondViewController. h "# import" NanaViewController. h "# import" SettingViewController. h "@ interface BeyondViewController () @ end @ implementation BeyondViewController-(void) viewDidLoad {[super viewDidLoad]; NSLog (@" view did loaded "); // The images in tabbarItem in UITabbarController must be processed by special APIs before they can be displayed normally. UIImage * img = [UIImage imageNamed: @ "home"]; UIImage * img_selected = [UIImage imageNamed: @ "home_s"]; // sets the image rendering mode img = [img imageWithRenderingMode: rendering]; // sets the image rendering mode img_selected = [img_selected imageWithRenderingMode: uiimagerenderingmodealsorwayiginal]; // construct a UITabBarItem * item = [[UITabBarItem alloc] initWithTitle: @ "image: img selectedImage: img_selected]; // set the tabBarItem attribute self of the current controller. tabBarItem = item; self. tabBarItem. title = @ "Homepage"; self. tabBarItem. badgeValue = [NSString stringWithFormat: @ "% d", 1]; // by default, after the app runs, only the view did load method of the first controller is executed. Therefore, to obtain all controllers in the UITabBarController container, call a custom method of UITabBarController and set their own tabbaritem styles. // obtain the UITabBarController of the parent container first, the reference UITabBarController * parentCtrl = self. parentViewController; // obtain all the sub-controllers NSArray * children = [parentCtrl childViewControllers] in the container UITabBarController; // call the custom method of the corresponding sub-controller, set their own tabbaritem style NanaViewController * nanaVC = (NanaViewController *) [children objectAtIndex: 1]; [nanaVC setTabBarItemDIY]; // call the custom method of the corresponding sub-controller, set their own tabbaritem style SettingViewController * setVC = (SettingViewController *) [children objectAtIndex: 2]; [setVC setTabBarItemDIY];} @ end
NanaViewController. h
//// NanaViewController. h // 17 _ controller switch 2_tabbarController // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface NanaViewController: UIViewController // custom method, set your own tabbaritem style-(void) setTabBarItemDIY; @ end
NanaViewController. m
//// NanaViewController. m // 17 _ controller switch 2_tabbarController // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "NanaViewController. h "@ interface NanaViewController () @ end @ implementation NanaViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. NSLog (@ "view did loaded 2");} // custom method, set your own tabbaritem style-(void) setTabBarItemDIY {// The images in tabbarItem in UITabbarController must be processed by a special API before UIImage * img = [UIImage imageNamed: @ "nana"] can be displayed normally. UIImage * img_selected = [UIImage imageNamed: @ "nana_s"]; // set the image rendering mode img = [img imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]; // sets the image rendering mode img_selected = [img_selected failed: Failed]; // The constructor generates UITabBarItem * item = [[UITabBarItem alloc] initWithTitle: @ "image: img selectedImage: img_selected]; // sets the tabBarItem attribute self of the current controller. tabBarItem = item; self. tabBarItem. title = @ "Nana"; self. tabBarItem. badgeValue = [NSString stringWithFormat: @ "% d", 2] ;}@ end
SettingViewController. h
//// SettingViewController. h // 17 _ controller switch 2_tabbarController // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface SettingViewController: UIViewController // custom method, set your own tabbaritem style-(void) setTabBarItemDIY; @ end
SettingViewController. m
//// SettingViewController. m // 17 _ controller switch 2_tabbarController // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "SettingViewController. h "@ interface SettingViewController () @ end @ implementation SettingViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. NSLog (@ "view did loaded 3");} // custom method, set your own tabbaritem style-(void) setTabBarItemDIY {// The images in tabbarItem in UITabbarController must be processed by a special API before they can be normally displayed. UIImage * img = [UIImage imageNamed: @ "setting"]; UIImage * img_selected = [UIImage imageNamed: @ "setting_s"]; // set the image rendering mode img = [img imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]; // sets the image rendering mode img_selected = [img_selected failed: Failed]; // The constructor generates UITabBarItem * item = [[UITabBarItem alloc] initWithTitle: @ "image: img selectedImage: img_selected]; // sets the tabBarItem attribute self of the current controller. tabBarItem = item; self. tabBarItem. title = @ "my"; self. tabBarItem. badgeValue = [NSString stringWithFormat: @ "% d", 3] ;}@ end
How can I obtain the specified viewController from a viewController when I use storyboard for iOS development?
UITableViewController * startingTableController = [self. storyboardinstantiateViewControllerWithIdentifier: @ "UITableViewController"];
[Self. view addSubview: startingTableController. view];
// InstantiateViewControllerWithIdentifier: The Identifier (Identifier) that defines the attributes of the form during design );
// [Self. storyboardinstantiateViewControllerWithIdentifier: @ "UITableViewController"]; it returns a controller object
// [Self. view addSubview: startingTableController. view]; Add the Controller view to the main window view. The disadvantage of this is that there is a blank area, which seems to be
The error message returned when the startingTableController taskbar is missing.
Set [self. view addSubview: startingTableController. view];
For
NSArray * viewController = [NSArray arrayWithObject: startingTableController];
[Self. pageViewController setViewControllers: viewControllerdirection: UIPageViewControllerNavigationDirectionForward animated: NO completion: NULL];
[Self addChildViewController: self. pageViewController];
[Self. view addSubview: self. pageViewController. view];
Can solve the blank Problem
How does IOS storyboard achieve two different viewcontroller jumps through judgment?
Storyboard is only used for interface layout, and the real judgment must be implemented in the code. NavigationController: push the viewcontroller according to the judgment. The code is better written by yourself, and the impression on yourself is the most profound. You can only remember what others wrote when you use it. You will never forget it for a while.