iOS Development-No. 05-Projects-01-building frameworks

Source: Internet
Author: User

Implementation: Imitation Sina Weibo


1. Project configuration


1> Canceling the screen

2> setting icons and starting pictures

3> Delete Mainstoryboard, all code creation




2. Add Tabbarcontroller


2.1 Creating Windows


1> in the Didfinishlaunchingwithoptions method, create a window, set the root controller, display the window




2> adding Tabbarcontroller sub-controllers






3> Extracting Duplicate code






Note: The above method limits each time you create a Uiviewcontroller , in practice, you need to set different controllers as Tabbarcontroller the child controller


4> improvements

Add controllers such as Hwhomeviewcontroller, pass to the above setting method after creation, set item and picture






2.2 Custom Hwtabbarviewcontroller


Note: The four controllers created above should belong to Tabbarcontroller, managed by Tabbarcontroller, and the function of Hwappdelegate agent is to create the window, set the root controller Tabbarcontroller, Do not need to tube tabbarcontroller inside the specific implementation, so the above code should not be placed in the Hwappdelegate method, should be extracted separately, Implementing the addition of a sub-controller in the Hwtabbarviewcontroller Viewdidload method






3. Add Navigationcontroller


3.1 Project Structure






3.2 Package Navigation controller




3.3 Navigation Controller Jump


1> Hwmessagecenterviewcontroller false data




2> Click cell to jump




4. Custom Navigation Controller


4.1 Setting up the navigation controller Leftbarbuttonitem and Rightbarbuttonitem




Arrow: Return to previous controller

Three point: Returns the root controller of the navigation controller


1> Basic Implementation




Note: for custom UIButton ( or other UI control ) , you must set its size, otherwise it may not show!!!


Note: UIView Write Classification

Note: When you need to modify the size of the control, you often need to remove the Frame , and then modify Frame , and then finally set Frame , more troublesome, could write a UIView the classification, package to modify the size of the method!




overriding the above attributes above Setter/getter method, set / Remove Control Frame , and then write the header file to the PCH file, the other classes can call directly




2> Other controllers also achieve the above requirements when jumping

If the other controller jumps, also need to implement set navigation controller for the same item, then directly copy the above code to each controller's Viewdidload method can be.

However, if a large number of controllers, the above duplicated code duplication too much, should be extracted.

Method One: Consider inheritance

However, for the controller, the general does not use inheritance, because there are many types of controllers, it is not possible to inherit all controllers from the same controller, through a controller to achieve unity.

For example: The navigation controller has both Uiviewcontroller and Uitableviewcontroller, and the need to set the navigation controller item, you can not inherit the same controller, set its item to achieve.

Scenario Two: Custom navigation controllers

override the push method to get the controller parameters passed in


4.2 Custom Navigation controller


1> in section 3.2, when the wrapper navigation controller is added to the Hwtabbrviewcontroller, the wrapped navigation controller is a custom navigation controller

2> Override the push method of a custom navigation controller !!!






Note 1 : The navigation bar for each controller now displays the same Item !

Note 2 : If a specific controller, its navigation bar needs to display another Item ( or empty ) , you can Viewdidload method, which overrides the actions in the custom navigation controller!

Note 3 : Will hide TabBar also encapsulates the actions of the custom navigation controller. Push method, but it needs to be placed in a call to the parent class Push method before, otherwise it will not be hidden!


5. Project Document Classification


Home (homepage), messagecenter (message), Discover (Discovery), Profile (Me): Four folders to store different function modules, which are divided into MVC structure

Main (Main): Store public modules, including MVC structure (main frame), category (category), Lib (third-party framework), other (Hwappdelegate, main.m)

Temp: Store temporary files, such as controllers for testing


6, the creation of package Uibarbuttonitem


6.1 Item Creation Analysis


Before setting the navigation bar item content, encapsulated into the push method of the custom navigation controller, but the navigation bar contents of each root controller, still need to set its item content.

method: Set in the Viewdidload method of the root controller (such as Hwhomeviewcontroller).




Note: The problem is that each root controller is required to set the left and right Item , and the code is in line with the navigation controller's Push method, set the Item the code repeats


6.2 Preliminary Package




will be Hwhomeviewcontroller in the Item The creation method is extracted, but this only guarantees Hwhomeviewcontroller can be created quickly in other controllers and still require duplicate code creation.


6.3 Creating Uibarbuttonitem categories




Note: Be sure to add Target parameter, which is used to represent which object, if the above code is copied directly over the Self , it causes the click Item when calling the category of the Action Method ( belongs to controller, not Item) , the program crashes!!! and place the header file in the PCH file. when you need to create the Item , call the method of classification directly!!!


Such as:



7. Summary




8. Set the navigation bar theme




Note: The right side of the navigation bar is set in the message controller Item ( write private Messages ) do not enable, if the enable = NO put in Viewdidload method, the body is too late to render, will not show gray, should be placed in Viewwillappear method in




note 1 view uses lazy loading, creating a view viewdidload method, previously in tabbarcontroller ADDCHILDVC method, set each view viewdidload method, set enable item no GRAY display!!!




Note 2 : And if a random color is set, the four controller View all are created in a breath ( the viewdidload method is called ) , this is not the case, you should use the appropriate controller to create the controller View , the code that sets the random color is commented out, and the settings can be Item of the Enable put in Viewdidload Method!


iOS Development-No. 05-Projects-01-building frameworks

Related Article

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.