2012-11-28 107 views
0

這些「管道」字符出現在我的表格視圖的某些單元格中,但僅在iOS 6上。第一個屏幕截圖顯示了iOS 6上的問題,下方的屏幕截圖是iOS 4.3:iOS 6上奇怪的tableViewCell問題

我很感激提供的任何幫助。

這裏是我使用的代碼:

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", indexPath.section, indexPath.row]; 

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if(cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     UIView *clearColor = [[UIView alloc] init]; 
     clearColor.backgroundColor = [UIColor clearColor]; 
     cell.selectedBackgroundView = clearColor; 
    } 

    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 243.5, 25)]; 
    [label1 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]]; 
    [label1 setTextColor:[UIColor blackColor]]; 
    label1.text = [[self.tableDataSource objectAtIndex:indexPath.row] objectForKey:@"Name"]; 
    [cell addSubview:label1]; 

    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(253.5, 10, 243.5, 25)]; 
    [label2 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]]; 
    [label2 setTextColor:[UIColor blackColor]]; 
    label2.text = [[self.tableDataSource objectAtIndex:indexPath.row] objectForKey:@"Email"]; 
    [cell addSubview:label2]; 

    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(507, 10, 243.5, 25)]; 
    [label3 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]]; 
    [label3 setTextColor:[UIColor blackColor]]; 
    label3.text = [[self.tableDataSource objectAtIndex:indexPath.row] objectForKey:@"Phone"]; 
    [cell addSubview:label3]; 

    UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(760.5, 10, 243.5, 25)]; 
    [label4 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]]; 
    [label4 setTextColor:[UIColor blackColor]]; 
    label4.text = [[self.tableDataSource objectAtIndex:indexPath.row] objectForKey:@"Business"]; 
    [cell addSubview:label4]; 

    return cell; 
} 

點擊圖片

enter image description here

enter image description here

回答

1

原來我必須設置每個標籤的背景顏色清除:

label.backgroundColor = [UIColor clearColor]; 
1

您使用UILabels的具體原因是什麼?我檢查了我的iOS6應用程序的代碼,並使用了NSStrings。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *newTitle = @"my string"; 
    cell.textLabel.text = newTitle; 
} 
+0

他需要在每個單元格中顯示4個不同的數據,這就是他使用四個標籤的原因。你可以使用'cell.textLabel.text'添加一個數據。 –

1

組清晰的背景顏色標籤

label.backgroundColor = [的UIColor clearColor];