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,
- In the Viewdidload:
- [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (back) name:@ "Backback" object:nil];
- -(void) back
- {
- [Self dismissviewcontrolleranimated:yes];
- }
Pushviewcontroller, Popviewcontroller, Presentviewcontroller, Dismissviewcontroller---Summary of view jumps