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

        }

        

    }

  • 相关阅读:
    20175330第九周学习总结
    20172326 《程序设计与数据结构》第十周学习总结
    20172326 《程序设计与数据结构》第九周学习总结
    20172326『Java程序设计』课程结对编程练习_四则运算第二周阶段总结
    《程序设计与数据结构》第八周学习总结
    结对编程-四则运算 第一周总结
    《程序设计与数据结构》实验2报告
    《程序设计与数据结构》第七周学习总结
    20172326 2017-2018-2 《程序设计与数据结构》第7周课堂测试修改报告
    《程序设计与数据结构》第六周学习总结
  • 原文地址:https://www.cnblogs.com/wujie123/p/5293746.html
Copyright © 2011-2022 走看看