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;

    }

  • 相关阅读:
    不同权限访问详细细节
    文件搜索器
    java中依赖、关联、聚合
    子类重写父类成员方法
    java中子类对父类中的私有变量和私有方法有拥有权无使用权
    shell脚本在CentOS7自动更包
    LR虚拟用户已设置集合点,但controller无法设置集合点策略的解决方案
    LR工具使用之场景设置
    LR集合点策略
    LR录制附件上传后,回放报错
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5785017.html
Copyright © 2011-2022 走看看