iOS Development Project-02 adding sub-controllers and project tiering

Source: Internet
Author: User

iOS Development Project-02 adding sub-controllers and project tiering

First, add a sub-controller

1. Setting the root controller (custom)

Description: Analyze Sina Weibo application and observe its overall construction level. and the controller of the system can not meet the needs of the project development, here the project has the original controller deleted. Define a Tabbarviewcontroller class yourself. Let this class act as the root Controller for window windows.

YYAPPDELEGATE.M File Code:

1 #import "YYAppDelegate.h" 2 #import "YYTabBarViewController.h" 3  4 @implementation yyappdelegate 5  6-(BOOL) AP Plication: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions 7 {8   9    / /1. Creating Windows     Self.window=[[uiwindow alloc]init];11     self.window.frame=[uiscreen mainscreen].bounds;12     13     //2. Setting the root controller of a window//    Uitabbarcontroller *TABBARVC =[[uitabbarcontroller alloc]init];15//    SELF.WINDOW.ROOTVIEWCONTROLLER=TABBARVC;     self.window.rootviewcontroller=[[yytabbarviewcontroller alloc]init];17     //3. display window     [ Self.window makekeyandvisible];20     return yes;21}22         

2. Create a new four custom controller

Description: According to the Function module division, divides the project into four big parts, respectively is the homepage, the message, the discovery and "I", according to the project need, the custom four sub-controller, carries on the management to these four modules respectively.

Customize four controllers to inherit from Uitableviewcontroller

In the controller (Yytabbarviewcontroller), add four sub-controllers

3. Copy the required picture material into the project

Recommendation: When copying images, it is recommended to use a hard disk copy of the hard disk, that is, in the Finder.

4. Modify the System plugin

In the project, it is often used to classify (such as the use of a self-defined uiimage in this project), but when we use this classification method, we can only hint that the plugin may not have smart hints, then in this case you may try to modify the plugin.

(1) Find the installation path of the plugin in Xcode

Hint: Xcode plug-in Installation path:/users/User name/Library/Application Support/developer/shared/xcode/plug-ins

(2) Show Package Contents

(3) Modify the Plist file

Second, the implementation of the Code

YYTABBARVIEWCONTROLLER.M file

 1//2//YYTABBARVIEWCONTROLLER.M 3//02-Weibo add sub controller and set item structure 4//5//Created by Apple on 14-7-3. 6//Copyright (c) 2014 itcase. All rights reserved. 7//8 9 #import "YYTabBarViewController.h" #import "YYHomeTableViewController.h" #import "Yydiscoverviewcontroller . h "#import" YYMessageViewController.h "#import" YYProfileViewController.h "#import" Uiimage+extension.h "15 16 @ Interface Yytabbarviewcontroller () @end19 @implementation YYTabBarViewController21-(void) VIEWDIDLOAD24 {2 5 [Super VIEWDIDLOAD];26//Add four sub-controllers Yyhometableviewcontroller *home=[[yyhometableviewcontroller Alloc]init];     [Self addonechildvc:home title:@ "Home" imagename:@ "Tabbar_home" selectedimagename:@ "tabbar_home_selected"];29 30 Yymessageviewcontroller *message=[[yymessageviewcontroller alloc]init];32 [self addonechildvc:message title : @ "message" imagename:@ "Tabbar_message_center" selectedimagename:@ "tabbar_message_center_selected"];33. YYDiscoveRviewcontroller *discover=[[yydiscoverviewcontroller alloc]init];35 [self addonechildvc:discover title:@ "discovery" imagename:@ "Tabbar_discover" selectedimagename:@ "tabbar_discover_selected"];36 Notoginseng yyprofileviewcontroller *profile =[[yyprofileviewcontroller alloc]init];38 [self addonechildvc:profile title:@ "Me" imagename:@ "Tabbar_profile"  selectedimagename:@ "tabbar_profile_selected"];39}40 41/**42 * Add a sub-controller *44 * @param CHILDVC sub-control Object 45 * @param title Title * @param imageName icon * @param selectedimagename When selected */49-(void) AddOne CHILDVC: (Uiviewcontroller *) CHILDVC title: (NSString *) title ImageName: (NSString *) ImageName Selectedimagename: (     NSString *) SelectedImageName50 {51//Random set sub-controller background color childvc.view.backgroundcolor=yyrandomcolor;53//Set Title 54 CHILDVC.TABBARITEM.TITLE=TITLE;55//Setup icon childvc.tabbaritem.image=[uiimage imagewithname:imagename];57//Set Icon UIImage *selectedimage=[uiimage Imagewi When selectedthname:selectedimagename];59 if (iOS7) {62//declare this picture with original (don't render) SelectedImage = [selected Image imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];64}65 childVc.tabBarItem.selectedImage = selecte DIMAGE;66 67 68//Add sub-controller to tabbar69 [self addchildviewcontroller:childvc];70}71 72 73//In IOS7, the selected Image is rendered again as blue 74//If you want to display the original, you have to tell it: Do not render the Add//Xcode plugin installation path:/users/User name/Library/Application support/developer/ Shared/xcode/plug-ins77 @end

UIImage classification

Uiimage+extension.h file

1//2//  Uiimage+extension.h 3//   4//5//  Created by Apple on 14-7-3.6//  Copyright (c) 2014 Heima. A ll rights reserved. 7//8  9 #import <uikit/uikit.h>10 @interface UIImage (Extension) + (UIImage *) Imagewithname: (NSString *) NA Me;13 @end

UIIMAGE+EXTENSION.M file

1//2//  UIIMAGE+EXTENSION.M 3//   4//5//  Created by Apple on 14-7-3.6//  Copyright (c) 2014 Heima. A ll rights reserved. 7//8  9 #import "Uiimage+extension.h" @implementation UIImage (Extension) + (UIImage *) Imagewithname: (Nsstrin G *) name13 {     UIImage *image = nil;15     if (iOS7) {//handling iOS7 nsstring *newname         = [name stringbyappendings tring:@ "_os7"];17         image = [UIImage imagenamed:newname];18     }19     if (image = = nil) {+ =         [ UIImage imagenamed:name];22     }23     return image;24}25 @end

Macro definitions in the configuration file

1//2//  Prefix Header 3//4//Contents of this file is implicitly included at the beginning of every  sour CE file. 5//6  7 #import <Availability.h> 8  9 #ifndef __iphone_5_010 #warning "This project uses features only avail Able in IOS SDK 5.0 and later. " #endif12 #ifdef __objc__14     #import <uikit/uikit.h>15     #import <foundation/foundation.h>16 17 Random color #define Yyrandomcolor [Uicolor colorwithred:arc4random_uniform ()/255.0 green:arc4random_uniform (256)/ 255.0 blue:arc4random_uniform (/255.0) alpha:1.0]19 20//Is iOS721 #define IOS7 ([[Uidevice Currentdevice]. Systemversion Doublevalue] >= 7.0) #endif

Operating conditions:

III. Planning Project Document structure

The development of this project is divided into modules, the file structure is as follows:

Tip: In the construction of the structure, you can create a new group in the project, after the group is complete, drag the corresponding files to the corresponding group, but the group is a virtual folder, by viewing the code of the file can be found, on the hard disk is essentially no sub-folder.

Recommendation: Group directly on the hard disk to resolve this issue.

iOS Development Project-02 adding sub-controllers and project tiering

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.