- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; 
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
 NS_AVAILABLE_IOS(6_0); // newer

第一个:

 

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; 

在初始化时候用:

static NSString *CellIdentifier = @"Cell";

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
      //设置你的cell
 
第二个 : - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
根据说明文档。要用注册办法
// Beginning in iOS 6, clients can register a nib or class for each cell.
// If all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned.
// Instances returned from the new dequeue method will also be properly sized when they are returned.
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
这里用
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier 注册
 
在TabelViewController出事化时候加入
self.backgroundColor = xxxx;
[self registerClass:[CustomCell class] forCellReuseIdentifier:@"CustomCell"];
这样在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath时候就可以省下
static NSString *CellIdentifier = @"Cell";
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
      //设置你的cell
 
 
 

相关文章:

  • 2021-04-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-12-08
  • 2022-12-23
  • 2021-06-07
  • 2021-09-30
相关资源
相似解决方案