iOS Stage Learning 30th Day notes (uiviewcontroller-uinavigationcontroller)

Source: Internet
Author: User
<span id="Label3"></p><p style="text-align: center;"><p style="text-align: center;">iOS Learning (UI) Knowledge Point Grooming</p></p><p><p></p></p><p><p>first, the introduction of Uiviewcontroller<br><br>1) Concept: Uiviewcontroller is the view controller, used to manage and control the page jump of a class, iOS using the MVC architecture, in the UI convenient</p></p><p><p>The specific performance is view plus viewcontroller. So Uiviewcontroller is one of the most common and important classes of iOS apps, and the general use is to write</p></p><p><p>A class inherits the Uiviewcontroller class. There is a very important attribute in Uiviewcontroller that is the view, which is the controller corresponding to the</p></p><p><p>View,mvc inside of V and C. You can manually create a view by overriding the Loadview method and then set it to the Controller's Properties.<br><br>2) Create a new class Firstviewcontroller base Viewcontroller This class to the Window's main view controller management for Example:</p></p><pre><pre><span style="color: #008080;">1</span> firstviewcontroller *FIRSTVC =<span style="color: #000000;"> [[firstviewcontroller alloc] init];</span> <span style="color: #008080;">2</span> Self.window.rootViewController = firstvc;</pre></pre><p><p><br>3) page Jump Method instance code<br><br>Method One:</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Initialize a second page</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span>_SECONDVC =<span style="color: #000000;"><span style="color: #000000;">[[secondviewcontroller alloc] init];</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">jump from the first page to the second page</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span>[self PRESENTVIEWCONTROLLER:_SECONDVC Animated:yes completion:^<span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #000000;"><span style="color: #000000;">}];</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">note: The Jump page objects here are generally defined as global or Error-prone</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">the corresponding jump return method:</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">back to Previous page Note: This method is written in A. M file on the second page</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span>[self Dismissviewcontrolleranimated:yes completion:^<span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span>}];</pre><p><p></p></p><p><p>Method Two:</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #000000;">[self.view addsubview:_secondvc.view];</span> <span style="color: #008080;">2</span> <span style="color: #008080;">3</span> <span style="color: #008000;">//</span> <span style="color: #008000;">the corresponding jump return method:</span> <span style="color: #008080;">4</span> <span style="color: #008000;">//</span> <span style="color: #008000;">back to previous page Note: This method is written on the second page of the. m file</span> <span style="color: #008080;">5</span> [self.view removefromsuperview];</pre></pre><p><p></p></p><p><p>4) Uiviewcontrller Initialization When the backgroundcolor default is nil, not clearcolor, so we have to initialize the view controller to the view controller to set</p></p><p><p>A color that is not clearcolor for example:</p></p><pre><pre><span style="color: #008080;">1</span> Self.view.backgroundColor = [uicolor whitecolor];</pre></pre><p><p><br>second, the introduction of Uinavigationcontroller<br><br>1) concept: Uinavigationcontroller is a navigation controller is a class to control the View page switch<br><br>2) Uinavigationcontroller Initialization of the instance code</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Initialize a view controller</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span>Firstviewcontroller *FIRSTVC =<span style="color: #000000;"><span style="color: #000000;">[[firstviewcontroller alloc] init];</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">initializing a navigation controller</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">the <span style="color: #008000;">Navigation controller itself has a stack container, the initialization of the time must be set up a Rootviewcontroller seat navigation controller base stack</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">initialization of the navigation controller must require a root view controller</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span>Uinavigationcontroller *nav =<span style="color: #000000;"><span style="color: #000000;">[[uinavigationcontroller alloc] initwithrootviewcontroller:firstvc];</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set the ROOTVC for the window to initialize the navigation controller instance for US</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span>Self.window.rootViewController = nav;</pre><p><p></p></p><p><p>3) pushviewcontroller Implement the page switch for example:</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #008000;">//</span> <span style="color: #008000;">Initialize Secondviewcontroller</span> <span style="color: #008080;">2</span> Secondviewcontroller *SECONDVC =<span style="color: #000000;"> [[secondviewcontroller alloc] init];</span> <span style="color: #008080;">3</span> <span style="color: #008080;">4</span> <span style="color: #008000;">//</span> <span style="color: #008000;">jump from Page 1 to page 2</span> <span style="color: #008080;">5</span> [self.navigationcontroller PUSHVIEWCONTROLLER:SECONDVC animated:yes];</pre></pre><p><p><br>4) popviewcontrolleranimated Implement page return for Example:</p></p><pre><pre><span style="color: #008080;"><span style="color: #008000;">return to previous VC</span><br>1</span><span style="color: #000000;">[self.navigationcontroller popviewcontrolleranimated:yes];</span> <span style="color: #008080;">2</span> <span style="color: #008000;">//</span> <span style="color: #008000;">Note: by navigating the controller push to another vc, it must be through the navigation controller pop back to the previous Page. </span> <span style="color: #008080;">3</span><span style="color: #008000;">//</span> <span style="color: #008000;">Two ways of jumping must be the corresponding return mode</span></pre></pre><p><p><br>5) poptorootviewcontrolleranimated jump directly to the root view controller of the navigation controller via the navigation controller, from the VC of the navigation Controller stack container n</p></p><p><p>For example:</p></p><pre><pre><span style="color: #008080;">1</span> [self.navigationcontroller poptorootviewcontrolleranimated:yes];</pre></pre><p><p></p></p><p><p>6) Viewcontrollers Gets the view controller array in the stack container of the navigation controller, for example:</p></p><pre><pre><span style="color: #008080;">1</span> nsarray *vcarr =<span style="color: #000000;"> self.navigationController.viewControllers;</span> <span style="color: #008080;">2</span> <span style="color: #008000;">//</span> <span style="color: #008000;">get a second view controller</span> <span style="color: #008080;">3</span> Uiviewcontroller *SECONDVC = [vcarr objectatindex:<span style="color: #800080;">1</span><span style="color: #000000;">];</span> <span style="color: #008080;">4</span> <span style="color: #008080;">5</span> [self.navigationcontroller POPTOVIEWCONTROLLER:SECONDVC animated:yes];</pre></pre><p><p></p></p><p><p>iOS Stage Learning 30th Day notes (uiviewcontroller-uinavigationcontroller)</p></p></span>

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.