zoukankan      html  css  js  c++  java
  • iOSbug日志

    试了三种方法 列在下面

    新建cell 文件

    包括.h .m .xib 

    然后在xib文件加上一个标签,目的是复用这个cell

    一,在要调用的listcell中初始化一个类方法

    //+(ListCell *)cellwithTableView:(UITableView *)tablaeView;

    //+(ListCell *)cellwithTableView:(UITableView *)tablaeView

    //{

    //    static NSString *identifier = @"ListCell";

    //    ListCell *cell = [tablaeView dequeueReusableCellWithIdentifier:identifier];

    //    if (!cell) {

    //        cell = [[[NSBundle mainBundle]loadNibNamed:@"ListCell" owner:self options:nil]lastObject];

    //    }

    //

    //    return cell;

    //

    //}

    二,直接在tableviewcontroller中注册nib

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        

        [self.tableView registerNib:[UINib nibWithNibName:@"ListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ListCell"];

        // Uncomment the following line to preserve selection between presentations.

        // self.clearsSelectionOnViewWillAppear = NO;

        

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

        // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    }

        ListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListCell"];

    三,用registerClass:[ListCell class]但使用之前必须初始化 cell

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

    {

        if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

            self = [[[NSBundle mainBundle]loadNibNamed:@"ListCell" owner:self options:nil]lastObject];

        }

        return self;

    }

    三种方法结果一样

    ps:注意,awakefromnib方法在每一次调用cell的时候都会用 

    输出结果如下

  • 相关阅读:
    magento删除local.xml后必须要页面安装
    magento后台无法打开
    ubuntu安装phpmyadmin
    数据结构有关于最优二叉树——最优哈夫曼树的建立过程和哈夫曼编码
    计算后缀表达式的过程(C#)
    mysql语句的相关操作整理
    mysql在控制台里出现中文问号问题
    Wampserver由橙变绿的解决过程
    重装win7系统的过程
    数据结构(C#):图的最短路径问题、(Dijkstra算法)
  • 原文地址:https://www.cnblogs.com/adodo/p/5237180.html
Copyright © 2011-2022 走看看