Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c iOS7自定义UITableViewCell ui对象将不会显示在UITableViewController中_Objective C_Ios7_Uitableview - Fatal编程技术网

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

Objective c iOS7自定义UITableViewCell ui对象将不会显示在UITableViewController中,objective-c,ios7,uitableview,Objective C,Ios7,Uitableview,我创建了一个自定义的UITableViewCell,它与iOS6完美配合,现在与iOS7配合使用时,我只得到标准的白色背景,没有任何自定义的cell UI对象 我注意到苹果为UITableView引入了一个新的视图,但我应该如何处理它呢 我试过: - cell.contentView.backgroundColor = [UIColor clearColor]; within UITableViewController cellForRowAtIndexPath but w

我创建了一个自定义的
UITableViewCell
,它与iOS6完美配合,现在与iOS7配合使用时,我只得到标准的白色背景,没有任何自定义的cell 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)];
}
有人知道我能做什么吗

屏幕: 1.看来

  • 所以看起来应该是这样的

  • 可能的复制不是真的!我用[cell setBackgroundColor:[UIColor clearColor]]尝试了该解决方案;结果是,我从自定义单元格中获得了一个黑色背景,但没有ui对象。在iOS6中,它可以完美地工作:(您需要将它放入
    -tableView:willDisplayCell:forrowatinexpath:
    方法中。是吗?还没有!您使用“放入”是什么意思,就像接受的答案一样:
    -(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)单元格forrowatinexpath:(NSIndexPath*)indexPath{[cell setBackgroundColor:[UIColor clearColor]];}