zoukankan      html  css  js  c++  java
  • static NSString *ID的改进

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

        

       static NSString *ID = @"testcell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];

        cell.textLabel.text = @"test";

        return cell;

    }

    上面这段代码你可能已经,行云流水于指尖。

     

     

    其实下面这样写也是对的

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

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testcell" forIndexPath:indexPath];

        cell.textLabel.text = @"test";

        return cell;

    }

     

    OC中如果直接这样定义字符串 @"testcell"  ,那么这个字符串会被放到常量区,所以 不存在反复创建的说法,这也是后来xcode版本中的改变,更早的xcode是不支持这种操作的。

  • 相关阅读:
    java内部私有类的构造函数
    java 日志
    java Random.nextInt()方法
    迭代器是快速失败的
    java Calendar
    java null?
    EclEmma
    Java泛型、泛型协变&&类型擦除
    java 声明实例化初始化三连
    写在Ruby之前。
  • 原文地址:https://www.cnblogs.com/songxing10000/p/4376324.html
Copyright © 2011-2022 走看看