The difference between Pushviewcontroller and Presentviewcontroller

Source: Internet
Author: User




The difference between Pushviewcontroller and Presentviewcontroller


2014-4-15 Read 3344 Comments 1


1.Use Uinavigationcontroller to return to the previous view using the pushviewcontroller:animated----[[Self navigationcontroller] Popviewcontrolleranimated:yes];---ps:push will automatically add the Back button in navigation's left bar, and it responds by returning. So generally do not need to write the return method, click the Back button. 2.Other times with presentmodalviewcontroller:animated [self Presentmodalviewcontroller:controller animated:yes];// Yes animated-----Return to previous view [self dismissmodalviewcontrolleranimated:yes]; 3.Switching views generally do not use Addsubviewuinavigationcontroller 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). Plus a


Using the Presentmodalviewcontrolleranimated 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  dismissmodalviewcontrolleranimated:no];//attention must be no!!.   
      [[nsnotificationcenter  defaultcenter] postnotificationname:@ "Backback"  OBJECT:NIL];  
}


Then in B


// In viewdidload:   
[[nsnotificationcenter defaultcenter] addobserver:self  Selector: @selector (back)  name:@ "Backback"  OBJECT:NIL];  
  
-( void) back  
{  
     [self  dismissmodalviewcontrolleranimated:yes];  
}  


1, Self.view Addsubview:view, Self.window Addsubview, it is important to note that this method just adds the page to the current page. It is not possible to use Self.navigationControler.pushViewController and Pushviewcontroller at this time. To switch between views using Pushviewcontroller and Popviewcontroller, you must require that the current view be a navigationcontroller. 

2, is to use Self.navigationcontroler Pushviewcontroller and Popviewcontroller for view switch, Pushviewcontroller is to enter the next view, Popviewcontroller is returned to the previous view. 

3, without Navigationcontroller navigation bar, use Self.presentviewcontroller and Self.dismissmodalviewcontroller. Specifically, use can be learned in detail from the documentation.

4. To use Pushviewcontroller and Pushviewcontroller 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 the view is a navigationcontroller. This method provides a good benefit, that is, you can control the screen rotation of each view uniformly.


The difference between Pushviewcontroller and Presentviewcontroller


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.