iOS development Project-40 building the cell's basic structure

Source: Internet
Author: User

iOS development Project-40 building the cell's basic structure

A simple explanation

1. strategy : for micro-Bo may appear in a variety of situations (only text, there is text map, there is a forwarding microblogging, etc.), one-time loading of the child control into the cell, for the space without data hidden. (Whatever child controls will be displayed after the cell, add all the possible child controls to the Contentview.)

Sample display for Weibo cell:

2. Steps to customize the cell:

1. Create a new subclass that inherits from Uitablecell 2. Initialize the child controls in the Initwithstyle: Method (1) All child controls that are likely to be displayed are added to Contentview (2) by the way, set some properties of the child controls (one-time settings: Fonts, Text color, background, etc.) 3. Provide two models (1) One is the data model (text data + picture data) (2) One is the frame model (data model + Frame+cell height of all child controls) 4. The cell should provide a Frame model property (1) passing the frame model to the cell (2) The cell sets the frame to the child control according to the frame model, sets the data to the child control according to the data Model (3) the cell determines which child control 5 is displayed and hidden according to the data model. Returns the cell's height in the agent method of the TableView

II. Structure Analysis of cell

Tip : If you need a "unified action" sub-control after the adjustment, consider adding them as a group to a view to manage them first. Do not skimp on UI controls, which do not account for memory, and that the picture occupies memory.

Only toolbars and Weibo specific content these two view is directly oriented to Contentview

Third, the new class, the top-level design of the class

Custom cell class, which inherits from UITableViewCell

Overall structure:

Code design in the class:

YYSTATUSCELL.M file

1 //2 //YYSTATUSCELL.M3 //34-Weibo building the basic structure of the cell4 //Custom Cell5 6 #import "YYStatusCell.h"7 #import "YYStatusDetailView.h"8 #import "YYStatusToolbar.h"9 Ten @interfaceYystatuscell () One@property (nonatomic,weak) Yystatusdetailview *DetailView; A@property (nonatomic,weak) Yystatustoolbar *toolbar; - @end -  the @implementationYystatuscell -  -- (ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier - { +Self =[Super Initwithstyle:style reuseidentifier:reuseidentifier]; -     if(self) { +         //Initializing child controls A          at         //1. Add Micro Blog Content - [self setupdetailview]; -          -         //2. Add a tool bar - [self setuptoolbar]; -     } in     returnSelf ; - } to  + /** Add Weibo details*/ --(void) Setupdetailview the { *Yystatusdetailview *detailview=[[Yystatusdetailview alloc]init]; $ [Self.contentview Addsubview:detailview];Panax Notoginsengself.detailview=DetailView; - } the  + /** Add tool bar*/ A-(void) Setuptoolbar the { +Yystatustoolbar *toolbar=[[Yystatustoolbar alloc]init]; - [Self.contentview Addsubview:toolbar]; $Self.toolbar=toolbar; $ } -  - @end

YYSTATUSDETAILVIEW.M file

1 //2 //yystatusdetailview.m3 //34-Weibo building the basic structure of the cell4 //5 6 #import "YYStatusDetailView.h"7 #import "YYStatusOriginalView.h"8 #import "YYStatusRetweetedView.h"9 Ten @interfaceYystatusdetailview () One@property (nonatomic,weak) Yystatusoriginalview *Originalview; A@property (nonatomic,weak) Yystatusretweetedview *Retweetedview; - @end - @implementationYystatusdetailview the  -- (ID) initWithFrame: (CGRect) Frame - { -Self =[Super Initwithframe:frame]; +     if(self) { -         //Initializing child controls +          A         //1. Add original Weibo at [self setuporiginalview]; -          -         //2. Add forward Weibo - [self setupretweetedview]; -     } -     returnSelf ; in } - /** Add original Weibo*/ to-(void) Setuporiginalview + { -Yystatusoriginalview *originalview =[[Yystatusoriginalview alloc]init]; the [self addsubview:originalview]; *Self. originalview=Originalview; $     Panax Notoginseng } - /** Add forward Weibo*/  the-(void) Setupretweetedview + { AYystatusretweetedview *retweetedview =[[Yystatusretweetedview alloc]init]; the [self addsubview:retweetedview]; +self.retweetedview=Retweetedview; - } $ @end

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.