Common functions of iOS navigation controllers and common attributes of navigationBar
Common Function triggering time of navigation Controller
Triggered when the View of the View Controller is about to appear
-(Void) viewWillAppear :( BOOL) animated
Triggered when View of the View Controller already appears
-(Void) viewDidAppear :( BOOL) animated
Triggered when the View of the View Controller is about to disappear
-(Void) viewWillDisappear :( BOOL) animated
Triggered when View of the View Controller disappears
-(Void) viewDidDisappear :( BOOL) animated
When the previous interface pushes the next interface, such as A push B, the four methods are executed in sequence A (ViewWillDisappear)> B (viewWillAppear)> A (viewDidDisappear)> B (viewDidAppear)
When the last interface pops the previous interface, such as B pop A, four methods are executed in sequence B (viewWillDisappear)> A (viewWillAppear)> B (viewDidDisappear)> A (viewDidAppear)
Common navigationBar attributes
1. Directly configure the navigationBar. Therefore, this operation will affect the content displayed on the navigationBar of each interface (the effect is the same)
1. Modify the navigationBar color
Self. navigationController. navigationBar. barTintColor = [UIColor redColor];
2. Disable the glass effect of navigationBar
Self. navigationController. navigationBar. translucent = NO;
3. Hide navigationBar
Self. navigationController. navigationBarHidden = YES;
4. Set an image for navigationBar
Images of different sizes have different effects:
1.320*44, will only attach a piece to the navigationBar
2. The height is less than 44 and greater than 44 and less than 64: The navigationBar is tiled and the status bar is displayed.
3. height equal to 64: the entire image is displayed on the navigationBar and status bar.
[Self. navigationController. navigationBar setBackgroundImage: [UIImage imageNamed: @ "32050"] forBarMetrics: UIBarMetricsDefault];
2. Customize the content displayed on the navigationBar of each interface separately (the content displayed on each interface is different)
Modify the navigationItem of the View Controller.
1. Set the title of the interface
Self. navigationItem. title = @ "Far East development ";
2. Modify titleView (intermediate display view)
UISegmentedControl * segment = [[UISegmentedControlalloc] initWithItems: @ [@ "group", @ "friend"]; self. navigationItem. titleView = segment; [segment release];
3. Modify the color of navigationBar self. navigationController. navigationBar. barTintColor = [UIColor whiteColor];
4. Modify the navigationBar. The content is displayed on the right.
UIBarButtonItem * right = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @ selector (add :)];
Self. navigationItem. rightBarButtonItem = right;
[Right release];
5. Modify the navigationBar. The content is displayed on the left.
UIBarButtonItem * left = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAddtarget: selfaction: @ selector (add :)];
Self. navigationItem. leftBarButtonItem = left;
[Left release];