zoukankan      html  css  js  c++  java
  • iOS 中自定义TableViewCell方法

    自定义cell时需要继承UITableViewCell.    

    举例:ZLSchoolListTableCell继承UITableViewCell

    ZLSchoolListTableCell.h文件

    #import <UIKit/UIKit.h>

    @class SchoolModel(模型);

    @interface ZLSchoolListTableCell : UITableViewCell

    +(instancetype)SchoolListWithTableView:(UITableView*)tableView;

    @property(nonatomic,strong)SchoolModel *Zlschool;(模型属性)

    @end

    ZLSchoolListTableCell.m文件

    #import "ZLSchoolListTableCell.h"

    #import "School.h"

    @interface ZLSchoolListTableCell()

    /** 图标 */

    @property (nonatomic, weak) UIImageView *iconView;

    /** 中文名 */

    @property (nonatomic, weak) UILabel *ChineseLabel;

    @end

    @implementation ZLSchoolListTableCell

    + (instancetype)SchoolListWithTableView:(UITableView *)tableView

    {

        static NSString *ID = @"ZLSchoolListTableCell";

        ZLSchoolListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

        if (cell == nil) {

            cell = [[ZLSchoolListTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

        }

        return cell;

    }

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    {

        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

        if (self) {

            [self setSubwiews];

            

        }

        return self;

    }

    - (void)setSubwiews{

       /** 图标 */

        UIImageView *iconView = [[UIImageView alloc] init];

        iconView.userInteractionEnabled = YES;

        [self.contentView addSubview:iconView];

        self.iconView = iconView;

        

       /** 中文名 */

        UILabel *nameLabel = [[UILabel alloc] init];

        nameLabel.textColor = IWTextColorTitle;

        nameLabel.font = IWTextFont16;

        [self.contentView addSubview:nameLabel];

        self.ChineseLabel = nameLabel;

    }

    - (void)setZlschool:(School *)Zlschool{

        _Zlschool = Zlschool;

        [self settingData];(设置数据)

        [self setSubwiewsFrame];(设置frame)

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

            ZLSchoolListTableCell *cell = [ZLSchoolListTableCell SchoolListWithTableView:tableView];

            SchoolModel*school =self.SChoolArry[indexPath.row];

            cell.Zlschool =school;

            return cell;

    }

  • 相关阅读:
    springboot热启动中那些不为人知的东东
    maven生命周期(lifecycle)—— maven权威指南学习笔记(四)
    maven 一个简单项目 —— maven权威指南学习笔记(三)
    maven 安装、运行、获取帮助 —— maven权威指南学习笔记(二)
    maven 简介 —— maven权威指南学习笔记(一)
    用opencsv文件读写CSV文件
    java基础之——DecimalFormat格式化数字
    Git学习
    Spring Boot教程(二十四)Web应用的统一异常处理
    Spring Boot教程(二十三)使用Swagger2构建强大的RESTful API文档(2)
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5785017.html
Copyright © 2011-2022 走看看