十一岁的加重songxing10000…… ------ 回到博主首页

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是不支持这种操作的。

posted @ 2015-03-29 21:05  songxing10000  阅读(205)  评论(0编辑  收藏  举报