Step for developing UITableView code custom cell in iOS

Source: Internet
Author: User

Although you can drag the control directly in UITableView to add a cell, the fatal disadvantage of this method is that the cell is fixed and the height of the cell is difficult to change. In actual development, it cannot meet our needs. For example:

*text;@property (nonatomic,copy) NSString *icon;@property (nonatomic,copy) NSString *name;@property (nonatomic,copy) NSString *picture;@property (nonatomic,assign,getter = isVip) BOOL *vip;

- (instancetype) initWithDict: (NSDictionary *)dict;+ (instancetype) weiboWithDict: (NSDictionary *)dict;

The internal implementation of the method will not be described here!

The frame model is created to encapsulate the process of calculating the positions of various controls in the cell. This reflects the idea of OOP programming!

In the Frame model, the Frame of each control is calculated and set based on the passed data model. Therefore, the Frame model must have a data model attribute, the frame calculation process of each control should be placed in the set Method of the model data attribute, and the height of the cell is calculated here.

*

 

Has the member attribute of the frame model type, which is used to set frame and data for each control in the cell.

Because the frame model has a data model, you do not need to introduce the data model here.

@property (nonatomic, strong) CLWeiBoFrame *weiboFrame;

Besides, a class method is provided to call the cell creation interface and the tableView parameter must be input. The tableView parameter is passed in to obtain the cell queue loop in tableView.

+ (instancetype)cellWithTableView:(UITableView* NSString *ID = *cell = (cell ===

-()initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *
=
 
 
         
UIImageView *iconView =
 
=
         
UILabel *nameView =
=
 
=
         
UIImageView *vipView =
= [UIImage imageNamed:
 
=
         
UILabel *textView =
= 
=
 
=
         
UIImageView *pictureView =
 
=
- () setCLWeiBoFrame:(MJStatusFrame *
=
 
 

 

 

 

 

*- (NSArray *
 (_weiboframes ==
 
 
         
NSString *path = [[NSBundle mainBundle]pathForResource:
         
NSArray *dictArray =
         
NSMutableArray *weibosFrameArray =
 (NSDictionary *dict 
             
CLWeiBo *weibo =
             
CLWeiBoFrame *weiboFrame =
=
 
 
         
_weiboframes =
 
 

 

 

- (NSInteger)tableView:(UITableView *
- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*
     
MJStatusCell *cell =
     
cell.statusFrame =
     
 

 

4.3 proxy method implementation

 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *
     
MJStatusFrame *statusFrame =
 

This is the end!

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.