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运行时内存划分
    浅谈Static
    浅谈同一家公司多个系统,共用登录用户名和密码
    浅谈Final
    浅谈StringBuffer
    浅谈加密算法BCrypt
    序列表 批量的含义
    安装activemq和java代码实现生产和消费
    Restful
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5785017.html
Copyright © 2011-2022 走看看