zoukankan      html  css  js  c++  java
  • iOS UITableView深入

    iOS 5.0以后苹果为了简化代码    在TableView向数据源请求数据之前使用-registerNib:forCellReuseIdentifier:方法为@“MY_CELL_ID”注册过nib的话,就可以省下每次判断并初始化cell的代码,要是在重用队列里没有可用的cell的话,runtime将自动帮我们生成并初始化一个可用的cell。

        [tableView registerClass:[YYTableViewCell class] forCellReuseIdentifier:@"uiy"];

        [tableView registerNib:[UINib nibWithNibName:@"YYTableViewCell" bundle:nil] forCellReuseIdentifier:@"uiy"];

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        YYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"uiy"];

        return cell;

    }

    从而省下了这句话

    if (!cell) { //如果没有可重用的cell,那么生成一个 

        cell = [[UITableViewCell alloc] init];

    }
  • 相关阅读:
    go基础_defer
    go基础_函数
    go基础_控制语句
    go基础_数组
    go基础_切片
    go命令行参数
    Hdu2795Billboard线段树
    Hdu1394Minimum Inversion Number线段树
    Hdu1754单点更新
    Hdu1166单点更新线段树
  • 原文地址:https://www.cnblogs.com/gaojingxuan/p/4929399.html
Copyright © 2011-2022 走看看