4-14 Learn

Source: Internet
Author: User

4-14 Learning Experience

First,the viewcontrollers attribute of Uitabbarcontroller

Uitabbarcontroller itself does not display any views, and if you want to display the view you must set its Viewcontrollers property (which defaults to show viewcontrollers[0]) This property is an array, It maintains a child view of all Uitabbarcontroller. In order to minimize the coupling between views, all Uitabbarcontroller related headings, icons and other information are controlled by the child view, Uitabbarcontroller only exist as a container.

Viewcontrollers Property

Setting the Viewcontrollers property also affects the currently selected Viewcontroller, and when you set this property Uitabbarcontroller first clears all the old Viewcontroller. Then deploy the new Viewcontroller, then try to re-select the last displayed Viewcontroller, if the Viewcontroller no longer exists, Will then try to select the same viewcontroller as the index and SelectedIndex, and if the index is not valid, the first Viewcontroller is selected by default.

SelectedIndex Property

This property allows you to get the currently selected Viewcontroller and set this property to display the Viewcontroller of the corresponding index in Viewcontrollers. If Moreviewcontroller is currently selected, the value obtained by this property is Nsnotfound, and the property cannot be set with the selected Moreviewcontroller. Setting index beyond the range of viewcontrollers will be ignored.

Two

Changes to the Tabbar API method:

-(void) Setfinishedselectedimage: (UIImage *) selectedimage withfinishedunselectedimage: (UIImage *) Unselectedimage NS _deprecated_ios (5_0,7_0, "use initWithTitle:image:selectedImage:or the image and SelectedImage properties along with Uiimagerenderingmodealwaysoriginal ");

This method has been deprecated in IOS7, and Apple recommends using InitWithTitle:image:selectedImage when initializing Tabbaritem:

Images are rendered in a way that does not use the default but uses uiimagerenderingmodealwaysoriginal

Three

1. Set the rendering mode of the UIImage: Uiimage.renderingmode

Coloring (Tint color) is one of the iOS7 interfaces. Set the rendering mode of the UIImage: Uiimage.renderingmode A significant change, you can set a UIImage Color to use the current view when rendering. UIImage added a read-only property: Renderingmode, corresponding to a new method: Imagewithrenderingmode:, It uses the Uiimagerenderingmode enumeration value to set the Renderingmode property of the picture. The enumeration contains the following values:

    1. Uiimagerenderingmodeautomatic//Adjusts the rendering mode automatically based on the environment in which the picture is used and the drawing context in which it is located.
    2. Uiimagerenderingmodealwaysoriginal//Always draws the original state of the picture without using tint Color.
    3. Uiimagerenderingmodealwaystemplate//Always draws a picture based on tint color, ignoring the color information of the picture.

The default value of the Renderingmode property is Uiimagerenderingmodeautomatic, which is whether uiimage uses tint color depending on where it is displayed. Other conditions can be seen in the following illustration

The following code shows how simple it is to create a picture using an established rendering pattern:

    1. UIImage *img = [UIImage imagenamed:@ "MyImage"];
    2. IMG = [img imagewithrenderingmode:uiimagerenderingmodealwaystemplate];

Four

Uitabbarcontroller How to add a child controller

/Add sub-controller to Itabbarcontroller

The first way of C.1

[TB ADDCHILDVIEWCONTROLLER:C1];

[TB ADDCHILDVIEWCONTROLLER:C2];

C.2 Second Way

[Email protected] [C1,C2,C3,C4];

Five

Parent-child Relationship Paradigm

Implementing a custom Container View controller is not a simple matter, mainly divided into two stages: the establishment of parent-child relationship and the dissolution of the parent-child relationship. If the PVC adds the CVC view as its own subview, the CVC must be the child View Controller of the PVC, which in turn is not necessarily true, such as Uinavigationcontroller, a view When the controller is push in, he and Navigationcontroller establish a parent-child relationship, but only the top view Controller is displayed, the bottom view The controller's view is removed from the display level of the container's view, and when a view controller is popped, the parent-child relationship is lifted with the Navigationcontroller.

Show a child view controller named content:

    1. [Self addchildviewcontroller:content]; 1
    2. Content.view.frame = [self frameforcontentcontroller];
    3. [Self.view AddSubview:self.currentClientView]; 2
    4. [Content didmovetoparentviewcontroller:self]; 3

1. Add content as Child View Controller,addchildviewcontroller: The interface establishes a logical parent-child relationship that can be accessed by Parentviewcontroller to its parent VC. Addchildviewcontroller: [Content willmovetoparentviewcontroller:self] is automatically invoked in the logic of the interface;

2. When a parent-child relationship is established, the content view is added to the parent VC's view hierarchy, which determines the area range of the content's view display.

3. Call the child's Didmovetoparentviewcontroller:, to notify her, complete the establishment of the parent-father relationship

To remove a child view controller:

    1. [Content Willmovetoparentviewcontroller:nil]; 1
    2. [Content.view Removefromsuperview]; 2
    3. [Content Removefromparentviewcontroller]; 3

1. Notify child, will be the dissolution of the father-son relationship, from the semantic can also be seen that the parent is nil

2. Remove the view of child from the hierarchy of the parent VC's view

3. The removefromparentviewcontroller will automatically invoke the [content] through the Removefromparentviewcontroller call to truly disassociate the relationship. Didmovetoparentviewcontroller:nil]

Six

Mount Viewcontroller from Storyboard: The ID of the Viewcontroller to be set, that is, the Storyboardid property in the storyboard interface properties

    1. uistoryboard* Mainstoryboard = [Uistoryboard storyboardwithname:@ "Mainstoryboard_iphone" bundle:nil];
    2. Leftviewcontroller *leftcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@ "LeftViewController" ];

Or:

    1. uistoryboard* Mainstoryboard = [Uistoryboard storyboardwithname:@ "Mainstoryboard_iphone" bundle:nil];
    2. Viewcontroller *leftcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@ "LeftViewController"];
    3. Uinavigationcontroller *navcontroller = [[Uinavigationcontroller alloc] initwithrootviewcontroller:leftcontroller];

  

4-14 Learn

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.