雖然在UITableView中可以直接拖控制項的方式進行添加cell,但是這種方式有一個致命的缺點,那就是cell是固定的,而且cell的高度難以更改。在實際的開發中並不能滿足我們的需求。比如以下:
*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;
方法內部實現就不再贅述了!
之所以建立frame模型,是為了封裝計算cell內各個控制項位置的過程。這體現了OOP的編程思想!
在Frame模型中,各個控制項的Frame會根據傳遞過來的資料模型進行計算設定,所以Frame模型中必須有一個資料模型屬性,且計算各個控制項的frame的過程應該放在模型資料屬性的set方法中,並且在這裡計算出cell的高度
*
有frame模型類型的成員屬性,用來對cell內的各個控制項設定frame 以及資料
因為frame模型中有一個資料模型 所以這裡無需再引入資料模型
@property (nonatomic, strong) CLWeiBoFrame *weiboFrame;
並且提供一個類方法,外界調用建立cell的介面,需要傳入參數tableView 。傳入tableView參數是為了能夠取得tableView內的cell隊列迴圈利用cell
+ (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 實現代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *
MJStatusFrame *statusFrame =
到此完畢!