To add a navigation bar to a single viewcontroller or to a appdelegate's main page, just add Navigationcontroller on Viewcontroller and add this Navigationcontroller
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Self.window = [[UIWindow alloc]initwithframe:[[uiscreen Mainscreen]bounds]];
Viewcontroller *mainview = [[Viewcontroller alloc]init];
Uinavigationcontroller *navi = [[Uinavigationcontroller Alloc]initwithrootviewcontroller:mainview];
Navi.navigationBar.backgroundColor = [Uicolor Bluecolor];
[Self.window Setrootviewcontroller:navi];
[Self.window makekeyandvisible];
return YES;
}
Settings for the font and color of the navigation bar
Self.navigationController.navigationBar.titleTextAttributes = [Nsdictionary dictionarywithobject:[uicolor Whitecolor] Forkey:uitextattributetextcolor]; ---font color
[Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ "Bj.png"] Forbarmetrics:uibarmetricsdefault]; -Background Color
The navigation bar jumps the page the consideration for to use the Navigationcontroller to jump the page, actually is carries on the stack and the stack operation, wants to release the memory, then when jumps back and forth, must consider several questions
1 A =>b=>c=>d,
D=>a with root view (HOME)
[Self.navigationcontroller Poptorootviewcontrolleranimated:yes];
D=>C (Each interface returns to the previous layer)
[Self.navigationcontroller Popviewcontrolleranimated:yes];
Return to the previous layer, and pass parameters
Cviewcontroller *CVC = [Cviewcontroller alloc]init];
Cvc.str = Self.str;
[Self.navigationcontroller POPTOVIEWCONTROLLER:CVC animated:true];
After returning to the previous layer, the previous page is displayed after the parameter is received and refreshed. Note that this should be judged in viewdidappear and receive the passed value
-(void) Viewdidappear: (BOOL) animated
{
Determine and receive the returned parameters
}
2 A =>b=>c=>d=>e,e=>b=>c=>e because B has already appeared before, can not be directly push to B in E, because that is already two B, increase memory, so in the jump, it is necessary to judge whether there has been a B before, appeared, then direct push. This push to the original B, does not regenerate a B in memory.
Nsarray *array = self.navigationController.viewControllers;
For (Uiviewcontroller *VC in array) {
if ([VC Iskindofclass:[bxxxviewcontroller Class]]) {
Push VC;
}
or know the pointers to each interface.
[Self.navigationcontroller
Poptoviewcontroller: [Self.navigationController.viewControllers
Objectatindex: ([self.navigationController.viewControllers Count]-4)]
Animated:yes];
In use, according to the needs of their own return layer, as long as a change of "4" this number can achieve the goal
IOS Viewcontroller Add navigation bar and return to jump selection