1

I created a custom UITableViewCell which works perfectly with iOS6, now with iOS7 i only get the standard white background without any of my customized cell UI objects.

I noticed that apple introduce a new view to the UITableView but how i should handle it ?

I tried:

    - cell.contentView.backgroundColor = [UIColor clearColor]; 
      within UITableViewController cellForRowAtIndexPath but without effect :(

UITableViewController:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PdfFile *file = [[pdfDS.ditcDocuments objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
    int maxCells = [[pdfDS.ditcDocuments objectAtIndex:indexPath.section] count];
    MedialoungeDocumentTableViewCell *cell = [[MedialoungeDocumentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DocumentTableCell"];

    [cell setDocumentTitle: file.fileTitle];
    [cell setFirstElement:(indexPath.row == 0) ? YES:NO];
    [cell setLastElement:(indexPath.row == (maxCells -1)) ? YES:NO ];
    NSString *subTitle = [file.fileSubtitle isEqualToString:@""]?@"":file.fileSubtitle;

    if([file.documentKind isEqualToString: PDFKIND_SUCCESS]){
        [cell setDocumentKind:PDFDOCTYPE_SUC];
        [cell setDocumentSubtitle:[NSString stringWithFormat:@"%@",subTitle]];
    }else if([file.documentKind isEqualToString:PDFKIND_SOLUTION]){
        [cell setDocumentSubtitle:[NSString stringWithFormat:@"%@", subTitle]];
        [cell setDocumentKind:PDFDOCTYPE_SOL];
    }else if([file.documentKind isEqualToString:PDFKIND_RESEARCH]){
        [cell setDocumentSubtitle:[NSString stringWithFormat:@"%@", subTitle]];
        [cell setDocumentKind:PDFDOCTYPE_WP];
    }

    cell.contentView.backgroundColor = [UIColor clearColor];
    return cell;

}

My custom UITableViewCell:

- (void)drawContentView:(CGRect)rect highlighted:(BOOL)highlighted {
    //// Color Declarations
    UIColor* grey = [UIColor colorWithRed: 0.178 green: 0.178 blue: 0.178 alpha: 1];
    UIColor* color4 = [UIColor colorWithRed: 0.611 green: 0.611 blue: 0.611 alpha: 1];
    UIColor* color6 = [UIColor colorWithRed: 0.529 green: 0.529 blue: 0.529 alpha: 1];
    UIColor* active = CUSTOM_COLOR(62, 62, 62, 1);
    //// Abstracted Attributes
    NSString* dcoumentTitleContent = self.documentTitle;
    NSString* subtitleContent = self.documentSubtitle;

    //// background Drawing
    UIBezierPath* backgroundPath = [UIBezierPath bezierPath];
    [backgroundPath moveToPoint: CGPointMake(8, 60)];
    [backgroundPath addLineToPoint: CGPointMake(8, 0)];
    [backgroundPath addLineToPoint: CGPointMake(30, 0)];
    [backgroundPath addLineToPoint: CGPointMake(930.00, 0)];
    if(lastElement){
        [backgroundPath addLineToPoint: CGPointMake(930.00, 50.00)];
    }else{
        [backgroundPath addLineToPoint: CGPointMake(930.00, 60.00)];
    }
    [backgroundPath addLineToPoint: CGPointMake(920, 60)];
    [backgroundPath addLineToPoint: CGPointMake(8, 60)];
    [backgroundPath closePath];
    if(highlighted){
        [active setFill];
    }else{
        [grey setFill];
    }
    [backgroundPath fill];

    //// colorStripe Drawing
    UIBezierPath* colorStripePath = [UIBezierPath bezierPath];
    [colorStripePath moveToPoint: CGPointMake(0, 60)];
    [colorStripePath addLineToPoint: CGPointMake(0, 0)];
    [colorStripePath addCurveToPoint: CGPointMake(10, 0) controlPoint1: CGPointMake(0,0) controlPoint2: CGPointMake(10, 0)];
    [colorStripePath addCurveToPoint: CGPointMake(10, 60) controlPoint1: CGPointMake(10, 0) controlPoint2: CGPointMake(10, 60)];
    [colorStripePath addLineToPoint: CGPointMake(0, 60)];
    [colorStripePath closePath];
    if(documentKind == PDFDOCTYPE_SOL){
        [CUSTOM_COLOR(SOL_COLOR_R, SOL_COLOR_G, SOL_COLOR_B, SOL_COLOR_A) setFill];
    }else if (documentKind == PDFDOCTYPE_SUC){
        [CUSTOM_COLOR(SUC_COLOR_R, SUC_COLOR_G, SUC_COLOR_B, SUC_COLOR_A) setFill];
    }else if(documentKind == PDFDOCTYPE_WP){
        [CUSTOM_COLOR(WP_COLOR_R, WP_COLOR_G, WP_COLOR_B, WP_COLOR_A) setFill];
   }

    [colorStripePath fill];

    //// dcoumentTitle Drawing
    CGRect documentTitleRect = CGRectMake(78, 7, 800, 40);
    [color4 setFill];

    if (SYSTEM_VERSION_LESS_THAN(@"7")){
        [dcoumentTitleContent drawInRect: documentTitleRect withFont: [UIFont fontWithName: @"Helvetica-Bold" size: 21.5] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentLeft];
    }else{
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
        [style setAlignment:NSTextAlignmentLeft];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        CGFloat fontSize = 21.5;
        UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];

        NSDictionary *dict=@{
                             NSFontAttributeName : font,
                             NSParagraphStyleAttributeName: style
                             };

        [dcoumentTitleContent drawInRect:documentTitleRect withAttributes:dict];
    }


    //// subtitle Drawing
    CGRect subtitleRect = CGRectMake(79, 32, 800, 22);
    [color6 setFill];
    if (SYSTEM_VERSION_LESS_THAN(@"7")){
        [subtitleContent drawInRect: subtitleRect withFont: [UIFont fontWithName: @"Helvetica-Bold" size: 13] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentLeft];
    }else{
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
        [style setAlignment:NSTextAlignmentLeft];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        CGFloat fontSize = 13.0;
        UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];

        NSDictionary *subDict=@{
                             NSFontAttributeName : font,
                             NSParagraphStyleAttributeName: style
                             };
        [subtitleContent drawInRect:subtitleRect withAttributes:subDict];

    }
    UIImage *img= [UIImage imageNamed:@"doc_icon.png"];
    [img drawInRect:CGRectMake(35, 10, 28, 40)];
}

Somebody any ideas what i could do?

Screens: 1. so it looks without cell ui objects

  1. so it should look like enter image description here
Vineet Singh
  • 4,775
  • 1
  • 28
  • 39
Tomben
  • 73
  • 7
  • possible duplicate of [UITableViewCell show white background and cannot be modified on iOS7](http://stackoverflow.com/questions/18878258/uitableviewcell-show-white-background-and-cannot-be-modified-on-ios7) – Kjuly Oct 13 '13 at 01:08
  • not really! i tried the solution with [cell setBackgroundColor:[UIColor clearColor]]; and the result is that i get a black background but no ui objects from my custom cell. In iOS6 it works perfectly :( – Tomben Oct 13 '13 at 01:16
  • You need to drop it in `-tableView:willDisplayCell:forRowAtIndexPath:` method. Have you? – Kjuly Oct 13 '13 at 01:22
  • not yet! What did you mean with "drop it in" – Tomben Oct 13 '13 at 06:50
  • Like the accepted answer does: `- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setBackgroundColor:[UIColor clearColor]]; }` – Kjuly Oct 13 '13 at 07:56
  • the same result :( i get only a black background but there are no ui objects... – Tomben Oct 13 '13 at 08:50
  • Black now? Where's your transparent background implemented? In cell's background view or content view? How about trying `- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setBackgroundColor:[UIColor colorWithWhite:1.f alpha:.5f]]; }` (set a transparent background for your cell)? – Kjuly Oct 13 '13 at 09:04
  • now it is white again. thats very curios :( The [cell setBackgroundColor:[UIColor clearColor]]; i implementet in the viewController – Tomben Oct 13 '13 at 11:31
  • Well, that's all I can help, maybe you can take a look at the UITableViewCell part of Apple's Official DOC and try to figure it out by yourself. Best wishes ;) – Kjuly Oct 13 '13 at 13:10
  • @Tomben Did you figure this out? I am facing the same issue. The UITableViewCell just doesn't show up. – zambrey Oct 18 '13 at 18:58

0 Answers0