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

        }

        

    }

  • 相关阅读:
    maven公共库
    java截取当前屏幕图片
    JAVE视频处理
    jar在maven仓库里面没有时 , 把jar导入本地仓库步骤
    3 .shell 之linux四剑客sed/grep/awk/find
    Spring学习(四)-基于注解的Bean管理
    Spring学习(三)-Bean的种类,作用域,生命周期
    Spring学习(一)-基本入门
    dubbo服务连接zookeeper报错:java.net.ConnectException: Connection refused
    idea-常用设置二
  • 原文地址:https://www.cnblogs.com/wujie123/p/5293746.html
Copyright © 2011-2022 走看看