【问题标题】:Trouble with tableview cell style - UITableViewCellStyleValue1表格视图单元格样式的问题 - UITableViewCellStyleValue1
【发布时间】:2010-12-23 18:16:07
【问题描述】:

我正在使用表格视图来显示列表。只有一个单元格有UITableViewCellStyleValue1。问题是向上/向下滚动时,详细的文本显示不好。这是代码。

// 自定义表格视图单元格的外观。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 静态 NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 如果(细胞 == 零){ 如果(indexPath.row == 0) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 重用Identifier:CellIdentifier] autorelease]; cell.textLabel.textColor = [UIColor whiteColor]; cell.accessoryType = UITableViewCellAccessoryDe​​tailDisclosureButton; cell.detailTextLabel.textColor = [UIColor yellowColor]; cell.detailTextLabel.text = @"描述"; } 别的 { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.textLabel.textColor = [UIColor whiteColor]; cell.accessoryType = UITableViewCellAccessoryNone; } } // 配置单元格。 cell.textLabel.text = [radioList objectAtIndex:indexPath.row]; 返回单元格; }

有人可以帮我吗?

【问题讨论】:

    标签: iphone tableview


    【解决方案1】:

    您没有正确处理单元格重用。尝试这样做,我认为您应该能够看到我在做什么不同。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
      UITableViewCell *cell = nil;
      if(indexPath.row == 0)
      {
       cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
       if (cell == nil)
       {
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier2] autorelease];
       }
       cell.textLabel.textColor = [UIColor whiteColor];
       cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
       cell.detailTextLabel.textColor = [UIColor yellowColor];
       cell.detailTextLabel.text = @"Description";
      }
      else
      {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.accessoryType = UITableViewCellAccessoryNone;
      }
     }
    
     // Configure the cell.
     cell.textLabel.text = [radioList objectAtIndex:indexPath.row];
     return cell;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多