zoukankan      html  css  js  c++  java
  • 自定义cell

    @interface MyCellTableViewCell : UITableViewCell

     //在单元格中添加子视图

    @property (strong,nonatomic) UILabel *MyLable;

    //为子视图赋值

    -(void)setCellinfo:(NSDictionary *)dic;

    @end

    @implementation MyCellTableViewCell

    //coder序列化

    //初始化单元格

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

    {

        

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

        //看调用父类方法

        if (self) {

            

            //初始化子视图

            self.MyLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 40)];

            self.MyLable.textAlignment = NSTextAlignmentCenter;

            self.MyLable.backgroundColor = [UIColor redColor];

            [self addSubview:self.MyLable];

        }

        //self表示cell

        //self本身就是试图  添加视图

        return self;

    }

    -(void)setCellinfo:(NSDictionary *)dic

    {

        //通过字典指定关键字 为子视图赋值

        self.MyLable.text = dic[@"name"];

    }

    //导头文件

    #import "MyCellTableViewCell.h"

    @interface RootTableViewController : UITableViewController

    @property (strong,nonatomic) NSMutableArray *arrM;

     @end

    @implementation RootTableViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

       

        self.arrM = [NSMutableArray arrayWithCapacity:10];

        NSString *path = [[NSBundle mainBundle] pathForResource:@"city" ofType:@"plist"];

        //数据源    临时变量

        NSArray *tempArr = [NSArray arrayWithContentsOfFile:path];

    //    NSLog(@"%@",tempArr);

        //自己构造一个新的集合

        //集合每个元素都是字典

        for (NSString *cityName in tempArr) {

            NSMutableDictionary *tempdic = [NSMutableDictionary dictionaryWithCapacity:10];

            //通过name关键字可以获取cityname 为mylable赋值

            [tempdic setObject:cityName forKey:@"name"];

            //为自定义单元格的获取做准备工作

            //可以通过关键字key  。 NSClassFromString(iden)

            //通过此方法得到自定的cell类型

            [tempdic setObject:@"MyCellTableViewCell" forKey:@"MyCellTableViewCell"];

            [self.arrM addObject:tempdic];

    //        NSLog(@"%@",self.arrM);

        }

        

    }

  • 相关阅读:
    Linux服务器免密登录设置
    Docker 批量停止、删除容器和镜像
    python破解wifi密码
    python调用paramiko模块连接服务器
    Docker搭建redis-cluster集群三主三备
    Centos7.7搭建Prometheus2.0+Grafana监控Docker容器
    Centos7.7部署fastdfs分布式文件系统
    拉取git代码仓库项目到本地
    Seafile对接Amazon S3存储后端
    Centos7.x部署SeaFile私有网盘
  • 原文地址:https://www.cnblogs.com/wujie123/p/5293746.html
Copyright © 2011-2022 走看看