• 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;

    }

  • 相关阅读:
    io学习
    asp.net文件上传进度条研究
    asp.net页面中的Console.WriteLine结果如何查看
    谨慎跟随初始目的不被关联问题带偏
    android 按钮特效 波纹 Android button effects ripple
    安卓工作室 日志设置
    安卓工作室 文件浏览器 android studio File browser
    一个新的Android Studio 2.3.3可以在稳定的频道中使用。A new Android Studio 2.3.3 is available in the stable channel.
    新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial
    码云,git使用 教程-便签
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5785017.html
Copyright © 2020-2023  润新知