difference between presentViewController and UINavigationController?

前端 未结 4 1435
忘掉有多难
忘掉有多难 2020-12-01 04:35

Please tell the difference between presentViewController and UiNavigationController? Could I use presentViewController instead of

4条回答
  •  萌比男神i
    2020-12-01 05:09

    presentViewController offers a mechanism to display a so-called modal view controller; i.e., a view controller that will take full control of your UI by being superimposed on top of a presenting controller.

    UINavigationController offers a much more flexible mechanism where you can push a new controller, and later pop it, so to go back to the previous one, in a ordered way. Imagine that controllers in a navigation controller will just build a sequence from left to right.

    I think that presentViewController is most suitable for use with just one view controller being presented at a time. You can surely use it to stack more view controllers one on top of the other (and thus sort of "mimic" a poor-man's navigation controller), but my bet is you will quickly find something not working as you expected.

    Specifically, an example of such limitation is the following: when you dismiss a modal view controller (in order to "close" it), all of your modally presented view controllers (from the same presenting controller) will also be dismissed at once. So you simply will not be able to implement a "go back"/navigation like functionality.

    So, it depends on what you are trying to do.

提交回复
热议问题