iOS same interface Moda and push mode switch

Source: Internet
Author: User

For the new small white, before the push and modal understanding of the simple to stay in the push with the navigation controller, modal when you can use the navigation controller can also use the difference between the controller itself, such as heroes code common [Self.navigationer push ...] and [self present ....] And

[Self.navigationer present ...] (Forgive the pseudo-code not written in Xcode, believe it smart as you should so easy! ~~)

Needless to say, the simple difference between push is to get the controller's navigation controller by push to "push" to the next controller, the display of the next control of the navigation bar is actually the previous navigation bar, if it is present .... (modal) mode, a new navigation bar appears ... These basic, simple to you can spit groove points are often used to solve large problems, such as an interface in different interfaces, the need for you to use a push way to come in, and then click on the top left corner is push back, and the same interface in another interface interface, You need to use the modal way from the top down modal back, at this time, many of us should feel very confused force, the moment, make full use of push and modal navigation bar sub-control of the different points can be a perfect solution to this problem, All we need to do in our own interface controller. m file is the selector method that sets the icon on the left side of the navigation bar:

1. Set the navigation bar Back button:

    self. Navigationitem. Leftbarbuttonitem = [[uibarbuttonitem  alloc]initwithimage:[ Uiimage imagenamed:@ "Btn_return_gray" ] style:uibarbuttonitemstyleplain< span class= "s2" > target:self < Span class= "S1" >action: @selector (Toback)];

2. In the Selector method:

-(void) Toback

{

// judgment is to be push or be modal out ;

Nsarray *viewcontrollers=self. Navigationcontroller. Viewcontrollers;

if (viewcontrollers. Count>1) {

if ([Viewcontrollers objectatindex: viewcontrollers. Count-1]==self) {

//push Way

[self. Navigationcontroller popviewcontrolleranimated:YES];

}

}

else{

//present Way

[self. Navigationcontroller dismissviewcontrolleranimated:YES completion:nil];

}

}

In this way, the same interface can be perfectly docking different interface interface different conversion mode, the use of the principle is based on push and modal the biggest difference, push way is the stack bottom controller, which is the root controller first removed, the latest push out of the stack top controller to retain, Modal is covered by the way, so can be based on the Navigationviewcontroller sub-controller is not the bottom of the controller itself to determine whether the conversion mode is modal or push, which effectively solves the above problem.

PS: Here the requirements correspond to the development of the module, but if the single-person development, it is recommended to encapsulate the parent class, the method is written into the parent class, the adoption of inheritance can effectively solve all push,modal in the project development of the mode of switching problems.

iOS same interface Moda and push mode toggle

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.