First, Introduction
An IOS app rarely consists of a single controller , unless the app is incredibly simple
When there are multiple controllers in the app , We need to manage these controllers
When you have multiple view , you can use a large view to manage 1 or more small view
Controller is the same, with 1 controllers to manage the other multiple controllers
To facilitate management of the controller,IOS provides 2 more special controllers (" parent Controller")
Uinavigationcontroller
Uitabbarcontroller
second, the use of steps
- Uinavigationcontroller steps to use
- Initialize Uinavigationcontroller
- Set the rootviewcontroller for UIWindow to uinavigationcontroller
- Depending on the situation, add the corresponding number of sub-controllers by the push method
Third, Uinavigationcontroller 's view internal structure
Note : The height of thenavigationcontroller is Navigationbar , not including status bar Status
Iv. How to obtain the sub-controller How to get 1>
@property (nonatomic,readonly) Nsarray *childviewcontrollers
@property (nonatomic,copy) Nsarray *viewcontrollers;
Attention:
Childviewcontrollers: is a property in Uiviewcontroller and read-only
Viewcontrollers: Is the attribute in the Uinavigationcontroller
Therefore, adding a child controller can take advantage
Navc.viewcontrollers = @[vc1,vc2];
2> Bug
When the navigation controller adds two controllers using the animated form of push, and then uses Childviewcontrollers to get the child controller objects, when printing, it displays only one
Workaround : animate set to NO
Five, the principle of uinavigatio Ncontroller
The navigation controller is a stack structure ( advanced back-out ),
-
- Using the push method can push a controller into the stack, the last stack controller is the top controller, the controller is the stack bottom controller
The first controller into the stack is Rootviewcontroller
-
- Use the pop method to remove the controller
Method:
-
- Use The push method to push a controller into the stack
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
-
- Use the pop method to remove the controller
-
- Remove the controller from the top of the stack
-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;
-
- Back to the specified child controller
-(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
-
- Back to root controller (stack bottom controller)
-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;
Vi. Modifying the contents of the navigation controller
Set Title
Self.navigationItem.title
Self.title
Set left and Right buttons
Self.navigationItem.leftBarButtonItem
Self.navigationItem.leftBarButtonItems
Self.navigationItem.rightBarButtonItem
Self.navigationItem.rightBarButtonItems
set Title to Custom view
Self.navigationItem.titleView
Nav bar Color
[Self.navigationController.navigationBar Setbackgroundcolor:[uicolor Redcolor]; It's just the color of the navigation bar.
[Self.navigationController.navigationBar Settintcolor:[uicolor Redcolor]; Theme ( button ) color
[Self.navigationController.navigationBar Setbartintcolor:[uicolor Redcolor]; navigation bar + status bar color
set bar Opaque
Self.navigationController.navigationBar.translucent = NO;
Set Custom Caption Properties
Title
nsdictionary* attr = @{nsfontattributename: [Uifont systemfontofsize:10],nsforegroundcolorattributename: [UIColor Redcolor]};
[Self.navigationController.navigationBar settitletextattributes:attr];
Titleview
uilabel* Titlelabel = [[UILabel alloc] Initwithframe:cgrectmake (0, 0, 100, 44)];
Titlelabel.font = [Uifont boldsystemfontofsize:20];
Titlelabel.textcolor =[uicolor Orangecolor];
Titlelabel.textalignment = Nstextalignmentcenter;
Titlelabel.text = @ " custom title ";
Self.navigationItem.titleView = Titlelabel;
the navigation bar sets the custom picture as a button (the original image is not rendered )
uiimage* image = [UIImage imagenamed:@ "navigationbar_friendsearch_highlighted"];
image = [Image imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
Basic use of iOS development UI Chapter-navigationcontroller