IOS Viewcontroller Add navigation bar and return to jump selection

Source: Internet
Author: User

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

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.