Objective-c--ui Basic Development Day Nineth (QQ friends List)

Source: Internet
Author: User

First, the knowledge point:

1. Nested use of dual models

2, the button of the Alignment method

3, optimize the load of UITableView

4, the use of Layoutsubview

5, the cell's folding agent

Two, nested definitions of two models:

Note that the self.friends is not yet a dictionary-to-model operation

Second, how to define cell reuse

Method One

Qqcell *cell =[tableview Dequeuereusablecellwithidentifier:identifier];

/**

However, this method, if it is not defined in the Xib identifier is not reused, using method two for reuse

if (Cell==nil)

{

Cell=[[nsbundle mainbundle]loadnibnamed:@ "Qqcell" Owner:nil options:nil].lastobject;

}

*/

Method Two

/**

To TableView register a reused cell

FileName of the Nibname:xib

Bundle: Empty is the default current bundle

No xib registerclass assumed not associated with Xib

*/

uinib *nib=[uinib nibwithnibname:@ "Qqcell" bundle:nil];

[Self.tableview registernib:nib forcellreuseidentifier:@ "Qqcell"];

Method Two do not need to judge whether the cell is empty can be in the Cellforrowatindexpath in the cell is nil judgment can be omitted

Summarize:

Use class Registration

Self.tableview Registerclass:forcellreuseidentifier:

Register with Xib

uinib *nib =[uinib nibwithnibname: @ "Qqcell" bundle:nil];

[Self.tableview registernib:nib forcellreuseidentifier:@ "Qqcell"];

Third, the layout of the button

/**

Focus how to set the text and image are left-aligned in the button, and the image and text remain at a certain distance

1. Set Contenthorizontalalignment (Uicontrolcontenthorizontalalignmentcenter/left/right/fill)

2. Set the inner margin of text and image (Imageedgeinsets/titleedgeinsets)

*/

Headerbutton.contenthorizontalalignment=uicontrolcontenthorizontalalignmentleft;

Set the inner margin of the picture or text to use Imageedgeinsets/titleedgeinsets Uiedgeinsetsmake respectively

Headerbutton.imageedgeinsets = Uiedgeinsetsmake (0, 10, 0, 0);

Headerbutton.titleedgeinsets = Uiedgeinsetsmake (0, 15, 0, 0);

4.2) The rotation of the picture, the problem: The picture may appear after rotation of the tensile condition:

/**

In order to maintain the original shape after rotation (Contentmode)

Uiviewcontentmodescaletofill Stretch Fill

Uiviewcontentmodescaleaspectfit Self-adapting

Uiviewcontentmodescaleaspectfill Adaptive padding

Uiviewcontentmodecenter, keep the original size.

*/

HeaderButton.imageView.contentMode = Uiviewcontentmodecenter;

#pragma Mark discovers that the boundary portion of the parent view will be cut off. Modify Properties Clipstobounds

HeaderButton.imageView.clipsToBounds =no;

Iv. reuse of TableView (similar to cell reuse)

/**

1. Define a reuse identifier

2, go to the cache pool to find

3. Determine if it is empty

4. Assign a value to the Headerview and return

*/

static NSString *headeridentifier [email protected] "Headerview";

Headerview *headerview =[tableview Dequeuereusableheaderfooterviewwithidentifier:headeridentifier];

if (Nil==headerview)

{

Headerview=[[headerview Alloc]initwithreuseidentifier:headeridentifier];

}

Note which instantiation method is called in the Headerview class//Outside, then override which method

So use:

if (self =[super initwithreuseidentifier:reuseidentifier])

V. In Headerview, the reason that the loaded sub-view cannot be displayed: (Layoutsubview)

The reasons why view cannot be displayed are:

1. The same color as the parent view

2. Not added to Parent view

3. Frame not set

4. Transparency

5. Obscured by other controls

6, Hidden=yes

7, check the parent view of the above situation

Note: Using Subview is equivalent to making a strong reference to a control

Layer: The layout is called when the frame of the view has changed

/**

If the current frame is not taken at the time of instantiation

Or when the current frame has changed

Or when the money frame's bounds is all 0 o'clock

This method sets the control to the Inner Child view (frame).

*/

-(void) layoutsubviews

{#warning Be sure to call the method of the parent class because this is called when the frame changes, so it should not be done here to add only the frame settings, other things do not move

[Super Layoutsubviews];

Vi. Folding Proxy Add protocol for cell

1. Set proxy Properties

@class Headerview;

@protocol headerviewdelegate<nsobject>

-(void) Headerview: (Headerview *) Headerview Didclickbutton:(UIButton *) button;

@property (Nonatomic,weak) id

2. Notification Agent

-(void) Didclickbutton: (UIButton *) button

{if ([Self.delegate responstoselector: @selector (Headerview:didclickbutton:)])

{[Self.delegate headerview:self Didclickbutton:button];}}

3, abide by the protocol to implement proxy method in Viewcontroller

headerview.delegate=self;

-(void) Headerview: (headerview*) Headerview Didclickbutton: (uibutton*) button{

}

Tips:

Numberofrowsinsection returns 0 o'clock will not execute Cellforrowatindexpath

Vii. tip How to remove the section of the model from the agent and modify the variable (tag)

In the Viewforheaderinsection reuse method of TableView:

Get which group

Headerview.tag=section;

Get section in Protocol method

1. Get the value of section

Nsinteger section = Headerview.tag;

Nsinteger section = Headerview.tag;

2. Get Groupmodel

Groupsmodel *groupmodel = self.dataarray[section];

3. Modify the Isexplain variable in Groupmodel

Groupmodel.explain =!groupmodel.isexplain;

4, refresh the table, why explain is clearly set to Yes or useless, because TableView has been called numberofrowinsection method, to recall, you need to use reload refresh

[_tableview Reloaddata];

Nsindexset *indexset =[nsindexset indexsetwithindex:section];

[_tableview Reloadsections:indexset Withrowanimation:uitableviewrowanimationfade];

#pragma mark has a question here, why does the triangle image click once and add it once to show a status like the instant back? With the refresh of the reload, the refresh will cause all TableView code to be re-executed again.

Objective-c--ui Basic Development Day Nineth (QQ friends List)

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.