UI_UItableView_AutoCell (custom cell), custom uitableview

Source: Internet
Author: User

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.

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.