设置initwithstyle时

设置initwithstyle时

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellidenti = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellidenti];

    if(cell == Nil)
    {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidenti];
    }
    cell.textLabel.text = isActive?searchData[indexPath.row]:tableData[indexPath.row];
    cell.detailTextLabel.text = isActive?searchNumberData[indexPath.row]:tableNumberData[indexPath.row];
    return cell;
}

我没有完美的视野,我没有使用情节提要。

最佳答案

我在代码中观察到的两件事

1)使用correct way of cell reusability来使用dequeueReusableCellWithIdentifier(正如已经建议的那样)。还可以看看使用dequeueReusableCellWithIdentifier:forIndexPath:的单元格here的可重用性的另一种方式。

2)尝试使用nil而不是Nil。看看this thread

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellidenti = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidenti];

    if(cell == nil)
    {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidenti];
    }
    cell.textLabel.text = isActive?searchData[indexPath.row]:tableData[indexPath.row];
    cell.detailTextLabel.text = isActive?searchNumberData[indexPath.row]:tableNumberData[indexPath.row];
    return cell;
}

关于ios - 设置initwithstyle时,UITableViewCell不显示字幕:UItableviewsubtitle,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22293126/

10-13 02:47