zoukankan      html  css  js  c++  java
  • 关于tableview内cell自定义的注册以及创建

    自定义cell的方法主要有两种,storyboard以及xib(假设新建的是cellTableViewCell类)

      比较倾向于xib方式使用xib在xib文件内将自定义的cell绘制好后导入到调用文件中,并且要设置其ID

      在使用时候,需要注册:

      

      static BOOL regist = NO;

        if (regist == NO) {                            //注册xib控件

            [tableView registerNib:[UINib nibWithNibName:@"cellTableViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];//Cell为xib的id

            regist = YES;

        }

    注册以后的调用,使用id来获取:

    cellTableViewCell * temp = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    之后再对对象内的属性进行相关的设置

    最终返回temp对象;

     

     

    最近在使用过程中发现,如果一个表内要显示多个自定义的cell,那么上述方法,代码将会不少,可以使用

     [self.tableView registerNib:[UINib nibWithNibName:@"cell名称" bundle:nil] forCellReuseIdentifier:@"cell的标识"];

    写在viewdidload方法内,在表的代理方法内,就不需要再次注册cell

     
  • 相关阅读:
    纯快排
    Quick Sort(快速排序)
    归并排序 ALDS1_5_B:Merge Sort
    单调栈(POJ2559)
    Sequence
    Codeforces Round #503
    度度熊学队列
    Always Online hdu 6350
    Hills And Valleys
    Problem G. Depth-First Search
  • 原文地址:https://www.cnblogs.com/thxios/p/4755502.html
Copyright © 2011-2022 走看看