Pushviewcontroller, Popviewcontroller, Presentviewcontroller, Dismissviewcontroller---Summary of view jumps

Source: Internet
Author: User

1.[Self.view Addsubview:view]; and the [Self.window Addsubview:view];It is important to note that this method simply adds the page (view) to the current page (view), the controller (Viewcontroller) or the original controller. At this time again with [Self.navigationcoller pushviewcontroller:animated:]; and [Self.navigationcontroller popviewcontrolleranimated:] ; It's not going to work. To switch between views using Pushviewcontroller and Popviewcontroller, you must require that the current view be a navigationcontroller. 2.If you have Navigationcontroller navigation bar, use[Self.navigationcoller pushviewcontroller:animated:];And[Self.navigationcontroller popviewcontrolleranimated:];To switch the view. Pushviewcontroller is entered into the next view, Popviewcontroller is returned to the previous view. 3.If there is no Navigationcontroller navigation bar, use[self presentViewController:animated:completion:];And[self dismissviewcontrolleranimated:completion:];Specifically, use can be learned in detail from the documentation. 4.To use Pushviewcontroller and Popviewcontroller for view switching, first make sure that the root view is Navigationcontroller, otherwise it is not available. Here is a simple way to make the view or the root view navigationcontroller. You define a subclass to inherit Uinavigationcontroller, and then wrap the view you want to show into this subclass so that you can make navigationcontroller. This method provides a good benefit, that is, you can control the screen rotation of each view uniformly. Package a controller (Uiviewcontroller) as a navigation controller (Uinavigationcontroller):

Uiviewcontroller *VC = [[Uiviewcontroller alloc] init];    

Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC];

1.Use----when using Uinavigationcontroller.go to the next view [Self.navigationcoller pushviewcontroller:animated:];----return to previous view [Self.navigationcontroller popviewcontrolleranimated:];----Ps:push will automatically add the Back button to the left bar of navigation, which responds by returning. So generally do not need to write the return method, click the Back button. 2.Other times (when the view is not Uinavigationcontroller, just a viewcontroller)----go to the next view: [Self presentViewController:animated:completion:];----return to Previous view: [Self dismissviewcontrolleranimated:completion:]; 3.switching views is generally less than addsubview Uinavigationcontroller is the navigation controller, if Pushviewcontroller, will jump to the next Viewcontroller, point back will return to the present Viewcontroller , if it is addsubview, in fact, or the current viewcontroller operation, but in the current view and "cover" a layer of view, in fact, the original picture in the following, do not see it. (Of course, you can also use Insertsubview Atindex that method to set the level of placement). 4.Plus one:

Using the Presentviewcontrolleranimated method from A->b->c, if you want to return a in C directly, you can do this:

Return event in C:

    • void back
    • {
    • [Self dismissviewcontrolleranimated:no];//note must be no!!
    • [[Nsnotificationcenter defaultcenter]postnotificationname:@ "Backback" object:nil];
    • }

      And then in B,

      1. In the Viewdidload:
      2. [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (back) name:@ "Backback" object:nil];
      3. -(void) back
      4. {
      5. [Self dismissviewcontrolleranimated:yes];
      6. }

Pushviewcontroller, Popviewcontroller, Presentviewcontroller, Dismissviewcontroller---Summary of view jumps

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.