UI_UItableView_AutoCell(自定义cell)
来源:互联网 发布:消除噪音软件 编辑:程序博客网 时间:2024/05/21 12:46
新建类
@interface YadongCell : UITableViewCell
方法
#pragma mark - 赋值方法
- (void)setCellDateWithYadong:(CinemaModel *)sender;
#pragma mark - 自定义高度
+(CGFloat)height;
#pragma mark - 封装
+ (instancetype)getYadongCellWithTtableView:(UITableView *)tableView;
方法实现
@interface YadongCell ()@property (nonatomic, strong) UILabel *nameLabel;@property (nonatomic, strong) UILabel *addrsLabel;@property (nonatomic, strong) UILabel *trafficLabel;@end
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self createLabel]; } return self;}#pragma mark - 创建 label- (void)createLabel{ self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width - 20, 30)]; // [self.contentView addSubview:self.nameLabel]; self.addrsLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 45, [UIScreen mainScreen].bounds.size.width - 20, 30)]; [self.contentView addSubview:self.addrsLabel]; self.trafficLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 80, [UIScreen mainScreen].bounds.size.width - 20, 30)]; [self.contentView addSubview:self.trafficLabel];}#pragma mark - 赋值方法- (void)setCellDateWithYadong:(CinemaModel *)sender{ self.nameLabel.text = sender.cinemaName; self.addrsLabel.text = sender.address; self.trafficLabel.text = sender.trafficRoutes;}#pragma mark - 自定义高度+(CGFloat)height;{ return 120.0f;}#pragma mark - 封装+ (instancetype)getYadongCellWithTtableView:(UITableView *)tableView{ static NSString *cellIdentifier = @"YadongCell"; YadongCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];// if (cell == nil) {// cell = [[YadongCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellIdentifier];// } return cell;}
// 给 tableView 注册,不用判断重用池是否为空(上面)[self.rootView.mainTableView registerClass:[YadongCell class] forCellReuseIdentifier:@"YadongCell"];
// 有几种类型,就要注册几种:可以注册无数次[self.rootView.mainTableView registerClass:[YadongCell class] forCellReuseIdentifier:@"UITableViewCell"];
实现cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YadongCell *cell = [YadongCell getYadongCellWithTtableView:tableView]; // 设置cell的值 [cell setCellDateWithYadong:self.dataArray[indexPath.row]]; return cell;}
0 0
- UI_UItableView_AutoCell(自定义cell)
- UI_UItableView_AutoCell(自定义cell 高度)
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- iOS cell自适应 自定义cell
- Cell报表 自定义公式
- 自定义cell另一种方法
- 使用xib自定义Cell
- IOS 根据输入值改变button颜色
- 性能优化系列总篇
- 继承
- 每天一个小知识点1(less整理)
- 六门武技,我需要你帮我找出其中的破绽
- UI_UItableView_AutoCell(自定义cell)
- C++新特性学习(2)
- 五猴分桃问题
- NetRouter创世纪
- java连接MYSQL
- 绿坝娘的加速器/绿坝娘的收藏夹
- IOS开发-08.自定义按钮
- 我需要你帮我找出其中的破绽
- iOS 各种传值方式