我在我的UITableViewCell
上有两个UILabels
。TableViewCell第一次不显示数据
我使用的故事板,我有自定义单元格这些标签如下图所示:
我cellForRowAtIndex
方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"cell";
NSLog(@"index = %ld",indexPath.row); //This logs correct 0,1,2 ..and so on
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
UILabel *lblCellTitle = (UILabel*)[self.view viewWithTag:1];
UILabel *lblCellDetail = (UILabel*)[self.view viewWithTag:2];
lblCellTitle.text = [arrtableDataHeading objectAtIndex:indexPath.row]; //this array contain valid values
lblCellDetail.text = [filterdInfo objectAtIndex:indexPath.row]; //this array contain valid values
return cell;
}
我的问题是,当我第一次打开我的控制器数据显示自第二个索引,最后我看到自定义标签名称如下所示:
而当我滚动,然后只有数据更新和随机顺序我无法获得正确的顺序数据。
当我调试时当indexPath
为0目标在UILabel
得到零,但是当它变成1我得到正确的值。
有些人告诉我使用cell.ContentView代替self.view将解决我的问题。但我很困惑这怎么可能。
您是否在Storyboard(“cell”)中设置了单元格标识符? – Mahesh
是的,我已经设置@Mahesh – NSUser