@SanMao
2015-08-05T16:34:35.000000Z
字数 3939
阅读 1540
UI
---所有cell的高度都是一样的
1.frame
UITableViewCell的子类,比如XMGTgCell
@interface XMGTgCell : UITableViewCell@end
-initWithStyle:reuseIdentifier:方法
/*** 在这个方法中添加所有的子控件*/- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {// ......}return self;}
-layoutSubviews方法 [super layoutSubviews]
/*** 在这个方法中计算所有子控件的frame*/- (void)layoutSubviews{[super layoutSubviews];// ......}
@class XMGTg;@interface XMGTgCell : UITableViewCell/** 团购模型数据 */@property (nonatomic, strong) XMGTg *tg;@end
- (void)setTg:(XMGTg *)tg{_tg = tg;// .......}
[self.tableView registerClass:[XMGTgCell class] forCellReuseIdentifier:ID];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{// 访问缓存池XMGTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 设置数据(传递模型数据)cell.tg = self.tgs[indexPath.row];return cell;}
2.Autolayout
UITableViewCell的子类,比如XMGTgCell
@interface XMGTgCell : UITableViewCell@end
-initWithStyle:reuseIdentifier:方法 添加子控件的完整约束
/*** 在这个方法中添加所有的子控件*/- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {// ......}return self;}
@class XMGTg;@interface XMGTgCell : UITableViewCell/** 团购模型数据 */@property (nonatomic, strong) XMGTg *tg;@end
- (void)setTg:(XMGTg *)tg{_tg = tg;// .......}
[self.tableView registerClass:[XMGTgCell class] forCellReuseIdentifier:ID];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{// 访问缓存池XMGTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 设置数据(传递模型数据)cell.tg = self.tgs[indexPath.row];return cell;}
UITableViewCell的子类,比如XMGTgCell
@interface XMGTgCell : UITableViewCell@end



@interface XMGTgCell()@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;@property (weak, nonatomic) IBOutlet UILabel *titleLabel;@property (weak, nonatomic) IBOutlet UILabel *priceLabel;@property (weak, nonatomic) IBOutlet UILabel *buyCountLabel;@end
@class XMGTg;@interface XMGTgCell : UITableViewCell/** 团购模型数据 */@property (nonatomic, strong) XMGTg *tg;@end
- (void)setTg:(XMGTg *)tg{_tg = tg;// .......}
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([XMGTgCell class]) bundle:nil] forCellReuseIdentifier:ID];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{// 访问缓存池XMGTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 设置数据(传递模型数据)cell.tg = self.tgs[indexPath.row];return cell;}
UITableViewCell的子类,比如XMGTgCell
@interface XMGTgCell : UITableViewCell@end



@interface XMGTgCell()@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;@property (weak, nonatomic) IBOutlet UILabel *titleLabel;@property (weak, nonatomic) IBOutlet UILabel *priceLabel;@property (weak, nonatomic) IBOutlet UILabel *buyCountLabel;@end
@class XMGTg;@interface XMGTgCell : UITableViewCell/** 团购模型数据 */@property (nonatomic, strong) XMGTg *tg;@end
- (void)setTg:(XMGTg *)tg{_tg = tg;// .......}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *ID = @"tg";// 访问缓存池XMGTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 设置数据(传递模型数据)cell.tg = self.tgs[indexPath.row];return cell;}