2013-06-12 3 views
0

셀의 contentView 속성을 사용하여 UILabels이 내 테이블보기 셀에 표시되지 않는 문제가 있습니다. UILabels은 UIImage를 셀에 추가하기 전에 표시되었습니다. 셀에 텍스트를 추가하고 cell.contenView를 사용하여 원하는 위치에 UILAbels을 배치 할 수있었습니다.contentView 속성을 사용하여 테이블보기 셀에 UILabels이 표시되지 않습니다.

감사합니다. 내가있는 contentView를 사용하는 대신 cell.textLabel.text = [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"title"]; 을 추가하면 셀 텍스트가있는 권리를 표시 또한

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

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier]; 


     UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, 320, 30)]; 

     titleLabel.tag = 234234; 
     titleLabel.backgroundColor = [UIColor clearColor]; 

     titleLabel.textColor = [UIColor whiteColor]; 
     [titleLabel setFont:[UIFont fontWithName:@"DIN" size:24]]; 
     titleLabel.layer.shadowColor = [[UIColor whiteColor] CGColor]; 
     titleLabel.layer.shadowOpacity = 0.7; 
     titleLabel.layer.shouldRasterize=YES; 

     [cell.contentView addSubview:titleLabel]; 

     UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 160, cell.bounds.size.width, 30)]; 

     detailLabel.tag = 345345; 
     detailLabel.backgroundColor = [UIColor clearColor]; 

     detailLabel.textColor = [UIColor whiteColor]; 
     [detailLabel setFont:[UIFont fontWithName:@"DIN" size:18]]; 
     detailLabel.layer.shadowColor = [[UIColor whiteColor] CGColor]; 
     detailLabel.layer.shadowOpacity = 0.7; 
     detailLabel.layer.shouldRasterize=YES; 

     [cell.contentView addSubview:detailLabel]; 

    } 


    UILabel *titleLabel = (UILabel *)[cell viewWithTag:234234]; 
    titleLabel.text = (NSString *)[[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"title"]; 

    UILabel *detailLabel = (UILabel *)[cell viewWithTag:345345]; 
    detailLabel.text = (NSString *)[[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"description"]; 


    NSString *imageUrlString = [NSString stringWithFormat:@"%@", [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"image"]]; 
    UIImage *cachedImage = [self.imageCache objectForKey:imageUrlString]; 
    if (cachedImage) 
    { 
     cell.imageView.image = cachedImage; 
    } 
    else 
    { 

     cell.imageView.image = [UIImage imageNamed:@"rest.jpg"]; // initialize the image with blank image as a placeholder 

     // download in the image in the background 

     [self.imageDownloadingQueue addOperationWithBlock:^{ 

      NSURL *imageUrl = [NSURL URLWithString:imageUrlString]; 
      NSData *imageData = [NSData dataWithContentsOfURL:imageUrl]; 
      UIImage *image = nil; 
      if (imageData) 
       image = [UIImage imageWithData:imageData]; 

      if (image) 
      { 

       [self.imageCache setObject:image forKey:imageUrlString]; // add the image to your cache 

       // finally, update the user interface in the main queue 

       [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
        // make sure the cell is still visible 

        UITableViewCell *updateCell = [tableView cellForRowAtIndexPath:indexPath]; 
        if (updateCell) 
         cell.imageView.image = image; 
       }]; 
      } 
     }]; 
    } 

    return cell; 
} 

:

여기 내 코드입니다.

detailLabel.textColor = [UIColor whiteColor]; 

당신은 흰색 배경에 흰색 글꼴 색상을 보여주기 위해 노력하고 :

enter image description here

+0

셀의 기본 이미지 뷰가 레이블을 중첩되어있을 수 있습니다. 이미지를 해당 이미지 뷰로 설정하지 말고 이미지 뷰의 배경색을 지우고 레이블이 제대로 표시되는지 확인하십시오. –

+0

@iUser 나는 그것을 시도했지만 아무런 표시가 나타나지 않습니다. cell.textLabel.text = [[publicDataArray objectAtIndex : indexPath.row]를 추가하면 objectForKey : @ "title"]; 콘텐츠를 사용하는 대신 셀 텍스트는 오른쪽에서 표시됩니다. 스크린 샷을 추가했습니다 – hanumanDev

답변

2

당신은 여기에 바보 같은 실수를 했습니까?

난 그냥 아래와 같은 코드를 테스트하고 올바르게 표시 :

이 이미지보기 위하여 만든 라벨을 가지고

UILabel *titleLabel; 
UILabel *detailLabel; 

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

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier]; 


     titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, 320, 30)]; 

     titleLabel.tag = 234234; 
     titleLabel.backgroundColor = [UIColor clearColor]; 

     titleLabel.textColor = [UIColor blackColor]; 
     [titleLabel setFont:[UIFont boldSystemFontOfSize:15]]; 
     titleLabel.layer.shadowColor = [[UIColor whiteColor] CGColor]; 
     titleLabel.layer.shadowOpacity = 0.7; 
     titleLabel.layer.shouldRasterize=YES; 


     [cell.contentView addSubview:titleLabel]; 

     detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 160, cell.bounds.size.width, 30)]; 

     detailLabel.tag = 345345; 
     detailLabel.backgroundColor = [UIColor clearColor]; 

     detailLabel.textColor = [UIColor blackColor]; 
     [detailLabel setFont:[UIFont boldSystemFontOfSize:15]]; 
     detailLabel.layer.shadowColor = [[UIColor whiteColor] CGColor]; 
     detailLabel.layer.shadowOpacity = 0.7; 
     detailLabel.layer.shouldRasterize=YES; 
      [cell.contentView addSubview:detailLabel]; 


     [cell.contentView bringSubviewToFront:titleLabel]; 
     [cell.contentView bringSubviewToFront:detailLabel]; 


     } 



    detailLabel = (UILabel *)[cell viewWithTag:345345]; 
    detailLabel.text = [_objects objectAtIndex:indexPath.row]; 


    titleLabel = (UILabel *)[cell viewWithTag:234234]; 
    titleLabel.text = [_objects objectAtIndex:indexPath.row]; 


    return cell; 
} 

EDIT 당신은 단지 두 줄을 추가해야합니다

[cell.contentView bringSubviewToFront:titleLabel]; 
[cell.contentView bringSubviewToFront:detailLabel]; 

또한 이미지 내용을 아래 그림과 같이 추가하십시오.

,
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 40 ,40)]; 
imgView.image = [UIImage imageNamed:@"img.png"]; 
[cell.contentView addSubview:imgvie]; 

스크린 샷 :

enter image description here

+0

감사합니다! 당신이 옳았! 이전에 표 셀 배경색을 선명한 색상으로 사용했지만 제거했습니다. 나는 색깔을 바꾸었고 그것은 지금 나타난다. 문제는 uiimage가 현재 텍스트 위에 있다는 것입니다. cell.imageView.image = image; 대신 contentView를 사용하여 이미지를 추가해야합니까? ? – hanumanDev

+0

내 수정 된 답변 plz 귀하의 문제를 확인하십시오 gona Fix :) –

관련 문제