IOS Study Notes (5)

Source: Internet
Author: User

Previous: http://www.bkjia.com/kf/201301/185018.html
UINavigationController implements navigation in App delegation. @ property (nonatomic, strong) UINavigationController * nav ;. in the m file, @ synthesize nav;-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. nav = [[UINavigationController alloc] initWithRootViewController: self. rootViewController]; [self. window addSubview: self. nav. view]; return YES;} in the viewController page-(void) ViewDidLoad {self. title = @ "hello World";} more deeply: drag the second view controller to the top of the controller 5 seconds after the first View Controller appears on the screen: first, put the second view controller in the first View Controller: # import "SecondViewController"-(void) pushSecondController {SecondViewController * secondController = [[SecondViewController alloc] initWithNibName: nil bundle: NULL]; [self. nav pushViewController: secondController animated: YES];}-(void) viewDidAppear :( BOOL) paramAnimated {[super viewDidAppear: para MAnimated]; [self defined mselector: @ selecter (pushSecondController) withObject: nil afterDelay: 5.0f];} since it can be dragged in, it can be removed:-(void) goBack {[self. nav Expiration: YES];}-(void) DidAppear :( BOOL) paramAnimated {[super viewDidAppear: paramAnimated]; [self defined mselector: @ selector (goBack) withObject: nil afterDelay: 5.0f];} adjust the sequence of the navigation controller in the View Controller. Use the viewControllers attribute of the UINavigationController class to obtain and modify the view associated with the navigation controller. The figure controller is arranged in ascending order:-(void) goBack {NSArray * currentControllers = self. nav. viewControllers; NSMutableArray * newControllers = [NSMutableArray arrayWithArray: currentControllers]; [newControllers removeLastObject]; self. nav. viewControllers = newControllers; // animation completed // [self. nav setViewControllers: newControllers animated: YES];} to push the last view controller from the hierarchy of the navigation controller associated with the current view controller, you can call this method in any view controller. To display an image in the navigation bar, use an image in the title of the current view of the navigation controller instead of the text-(void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor whiteColor]; UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (0.0f, 0.0f, 100366f, 40366f); imageView. contentMode = UIViewContentModeScaleAspectFit; UIImage * image = [UIImage imageNamed: @ "FullSizeLogo.png"]; [imageView setImage: image]; self. navigationItem. titleView = ImageView;} before using the UIBarButtonItem class to add a button in the navigation bar to create a navigation button: Create a UIBarButtonItem class instance and use the NavigationItem attribute of the view space to add a button to the navigation bar. The NavigationItem attribute allows us to set this navigation bar. This attribute has two attributes: rightBarButtonItem and leftBarButtonItem. Both attributes belong to the UIBarButtonItem class. -(Void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor whiteColor]; self. title = @ "hello World"; self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "right" style: UIBarButtonItemStylePlain target: self action: @ selector (adjust mright :)];}-(void) specify mright :( id) right {NSLog (@ "clicked rightButton");} method 1 of system button initialization: initWithBarButtonSystemItem: target: action: Initialization method self. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithBartButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @ selector (navigation mright :)]; The initialization button of the navigation button: typedef enum {UIBarButtonSystemItem Done/Cancel/Edit/Save/Add/FlexibleSpace/FixedSpace/Compose/Reply/Action/Organize/Bookmarks/Search/Refresh/Stop/Camera/Trash/Play/ pause/Rewind/FastForward/Undo/Redo/PageCurl/} UIBarBut TonSystemItem; system button Initialization Method 2: initWithCustomView: method (you can add UISwitch)-(void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor whiteColor]; self. title = @ "hello World"; UISwitch * mySwitch = [[UISwitch alloc] init]; mySwitch. on = YES; [mySwitch addTarget: self action: @ selector (SwitchChanged :) forControlEvents: UIControlEventValueChanged]; self. navigationItem. rightBarButtonItem = [UIBarB UttonItem alloc] initWithCustomView: mySwitch];} Now, test it. So let's make a demo of the up and down arrows. -(Void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor whiteColor]; self. title = @ "hello World"; NSArray * items = [[NSArray alloc] initWithObjects: [UIImage imageNamed: @ "UpArrow.png"], [UIImage imageNamed: @ "DownArrow.png"], nil]; UISegmentedControl * segmentedControl = [[UISegmentedControl alloc] initWithItems: items]; segmentedControl. segmentedControlStyle = UISegmentedControlStyl EBar; segmentedControl. momentary = YES; [segmentedControl addTarget: self action: @ selector (segmentedControlTapped :) forControlEvents: UIControlEventValueChanged]; self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] future: segmentedControl]; // set the animation // UIBarButtonItem * rightBarButton = [[UIBarButtonItem alloc] future: segmentedControl]; [self. navigationItem setRight BarButtonItem: rightBarButton animated: YES];} Use UITabBarController to display the multi-view controller AppDelegate. in h, @ class FirstViewController; @ class SecondViewController; @ property (nonatomic, strong) FirstViewController * firstViewController; @ property (non atomic, strong) SecondViewController * secondViewController; @ property (non atomic, strong) UITableBarController * tabBarController; AppDelegate. in the m file, @ synthesize firstViewController, se CondViewController, tabBarController; self. firstViewController = [[FirstViewController alloc] initWithNibName: nil bundle: NULL]; self. secondViewController = [[SecondViewController alloc] initWithNibName: nil bundle: NULL]; NSArray * twoViewControllers = [[NSArray alloc] initWithObjects: self. firstViewController, self. secondViewController, nil]; self. tabBarController = [[UITabBarController alloc] init]; [self. tab BarController setViewControllers: twoViewControllers]; when you run the program, there is no navigation. What should we do? Proceed to the next step. In AppDelegate. in h @ proterty (non atomic, strong) UINavigationController * nav; In AppDelegate. @ synthesize nav; self. firstNavigationController = [[UINavigationController alloc] initWithRootViewController: self. firstViewController]; self. secondNavigationController = [[UINavigationController alloc] initWithRootViewController: self. secondViewController]; NSArray * twoNavigationController = [[NSArray alloc] initWithOb Jects: self. firstNavigationController, self. secondNavigationController, nil]; self. tabBarController = [[UITabBarController alloc] init]; [self. tabBarController setViewControllers: twoNavigationController]; self. window addSubview: self. tabBarController. view]; tabbarItem attribute: firstViewController. m-(id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil {self = [super initWithNibName: nibNam EOrNil bundle: nibBundleOrNil]; if (self! = Nil) {self. title = @ "First"; self. tabBarItem. image = [UIImage image named: @ "FirstTb.png"];} return self;} secondViewController same as above

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.