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

        }

        

    }

  • 相关阅读:
    第12组 Beta冲刺 (4/5)
    第12组 Beta冲刺 (3/5)
    代码用辅助多了 基础的读取config都忘记了
    wpf 动态添加控件 通过xmal实习 c#代码插入控件
    C#里调用非托管的Dll -z注意 net版本
    动态调用 类库
    c#时间的生成
    c# 第三方 修改版本号 MSBuildTasks, 解决 通配符不匹配问题
    c#.exe以管理员身份运行
    log4
  • 原文地址:https://www.cnblogs.com/wujie123/p/5293746.html
Copyright © 2011-2022 走看看