Tips:dequeueReusableCellWithIdentifier:和dequeueReusableCellWithIdentifier:forIndexPath:

dequeueReusableCellWithIdentifier:forIndexPath:

官方解释是 iOS6后的新方法

This method dequeues an existing cell if one is available, or creates a new one based on the class or nib file you previously registered, and adds it to the table.
You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

dequeueReusableCellWithIdentifier:

Returns a reusable table-view cell object located by its identifier.

说明前者不需要判断cell 为nil,但需要注册,后者需要判断cell为nil,但不需要注册

Demo

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:indentify];
      if(cell == nil) {
             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];
       }
      return cell;
}
 // 创建tableView后马上可以调用该方法
 [tableView registerClass:[VSMessageFinaceBillCell class] forCellReuseIdentifier:@"cell"];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
      return cell;
}

你可能感兴趣的:(Tips:dequeueReusableCellWithIdentifier:和dequeueReusableCellWithIdentifier:forIndexPath:)