【问题标题】:Value stored to 'cell' is never read存储到“单元格”的值永远不会被读取
【发布时间】:2013-11-22 22:08:25
【问题描述】:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *customCell_Identifier = @"CustomCell";
    ThreePartitionCells *cell = (ThreePartitionCells *)[tableView dequeueReusableCellWithIdentifier:customCell_Identifier];    

    if (cell == nil) 
   {
      cell = (ThreePartitionCells *)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifier] autorelease];
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells" owner:self options:nil];
      cell =  [nib objectAtIndex:0];     
   }    

  [cell setSelectionStyle:UITableViewCellSelectionStyleNone];   
   NSLog(@"%@", [arrActivityList objectAtIndex:[indexPath row]]);

   NSString *strTemp = [NSString stringWithFormat:@"%@-%@", [[[[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:@"ITEMS"] objectForKey:@"Area"] objectForKey:@"AREANAME"] objectForKey:@"text"], [[[[[[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:@"ITEMS"] objectForKey:@"Area"] objectForKey:@"ITEMS"] objectForKey:@"Bin"] objectForKey:@"BIN_BARCODE"] objectForKey:@"text"]  ];

  cell.lblProductName.text = strTemp;
  cell.lblExpectedCount.text = [[[arrActivityList objectAtIndex:[indexPath row]]objectForKey:@"ProductName"]objectForKey:@"text" ];

  cell.lblCounted.text = [[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:@"Status"] objectForKey:@"text"];

  [cell.lblProductName setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
  [cell.lblCounted setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];

  return cell;
 }

我在分析这样的项目时收到警告“存储到‘单元格’的值永远不会被读取”。好吧!代码正在使用单元格,但在 if 块之外。我想消除这个警告!

有人可以帮我吗?

提前致谢:)

【问题讨论】:

  • 为什么要连续设置 cell = ... 2 次?第一个值当然不会被使用,因为它被第二个覆盖了;)
  • 标签compiler 应用于有关编译器编程的问题或有关编译器详细内部工作的问题。不要使用compiler 询问有关特定编译器的选项和设置的问题,请改用您感兴趣的编译器的名称。

标签: objective-c cocoa-touch compiler-errors xcode4.2 xcode5


【解决方案1】:

这里的问题:

if (cell == nil) 
   {
  cell = (ThreePartitionCells *)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifier] autorelease];

  NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells" owner:self options:nil];

  cell =  [nib objectAtIndex:0]; 
   } 

您从自定义类初始化单元格,然后从笔尖分配给单元格,这样您就失去了对第一个单元格的控制并且您没有使用第一个单元格。

试试这个:

if (!cell){
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells"
                                                 owner:self
                                               options:nil];
    for (id obj in nib) {
        if ([obj isKindOfClass:[ThreePartitionCells class]]) {
            cell = (ThreePartitionCells *)obj;
            break;
        }
    }
}

或:

if (!cell){
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells"
                                                 owner:self
                                               options:nil];
    cell = nib[0];
}

或:

if (!cell){
    cell = [[[ThreePartitionCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifierr] autorelease];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    相关资源
    最近更新 更多