UI_UItableView_AutoCell (custom cell), custom uitableview
New Class
@interface YadongCell : UITableViewCell
Method
# Pragma mark-Assignment Method
- (void)setCellDateWithYadong:(CinemaModel *)sender;
# Pragma mark-custom height
+(CGFloat)height;
# Pragma mark-encapsulation
+ (instancetype)getYadongCellWithTtableView:(UITableView *)tableView;
Method implementation
@interface YadongCell ()@property (nonatomic, strong) UILabel *nameLabel;@property (nonatomic, strong) UILabel *addrsLabel;@property (nonatomic, strong) UILabel *trafficLabel;@end
-(Instancetype) initWithStyle :( optional) style reuseIdentifier :( NSString *) reuseIdentifier {self = [super initWithStyle: style reuseIdentifier: reuseIdentifier]; if (self) {[createLabel];} return self;} # pragma mark-create 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-Assignment Method-(void) setCellDateWithYadong :( CinemaModel *) sender {self. nameLabel. text = sender. cinemaName; self. addrsLabel. text = sender. address; self. trafficLabel. text = sender. trafficRoutes ;}# pragma mark-custom height + (CGFloat) height; {return 1200000f ;}# pragma mark-encapsulation + (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 ;}
// Register tableView. You do not need to judge whether the reuse pool is empty (above) [self. rootView. mainTableView registerClass: [YadongCell class] forCellReuseIdentifier: @ "YadongCell"];
// There are several types to register: You can register countless times [self. rootView. mainTableView registerClass: [YadongCell class] forCellReuseIdentifier: @ "UITableViewCell"];
Implement cell
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {YadongCell * cell = [YadongCell sequence: tableView]; // set the cell value [cell sequence: self. dataArray [indexPath. row]; return cell ;}
Copyright Disclaimer: This article is an original outlan article and cannot be reproduced without the permission of the blogger.