iOS7自定义UITableViewCell ui对象不会在UITableViewController中显示

时间:2013-10-13 01:04:10

标签: objective-c ios7 uitableview

我创建了一个与iOS6完美配合的自定义UITableViewCell,现在使用iOS7我只获得标准的白色背景而没有任何自定义的单元UI对象。

我注意到苹果为UITableView引入了一个新视图,但我应该如何处理呢?

我试过了:

    - 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;

}

我的自定义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)];
}

有人有什么想法我能做什么?

屏幕: 它看起来如此 without cell ui objects

  1. 所以看起来应该是这样的 enter image description here

0 个答案:

没有答案