3

上記のエラーが発生しましたが、修正方法がわかりません。修正できるように、このエラーが発生した理由を誰かに教えてもらえますか?

コード自体が機能し、画像(テキストレイヤーを除く)を画面に描画するので、エラーを削除したいだけです。私はすでにスタックオーバーフローを検索し、「キャスト」を見つけましたが、このテクニックを試した後もエラーはまだあります。

メソッドを使っているからだと思います

[CardElementsCreationClass drawHeart]

[CardElementsCreationClass drawValueWithSuit:suit AndValue:value]

私の.m

#import "CardCreationClass.h"

@implementation CardCreationClass

//--------------------
//Create a card
//
+ (UIView *) newPlayingCardWithSuit:(NSString *)suit
                          AndValue:(NSString *)value {  
    //Create playing card UIVIew
    CGRect playingCardBounds = CGRectMake(100, 50, 100, 200);
    //CGPoint playingCardPosition = CGPointMake(100, 50);

    UIView* playingCard = [[UIView alloc] initWithFrame:playingCardBounds];

    //CREATE BACK OF CARD
    //

    //CREATE FRONT OF CARD
    CALayer* front = [CALayer layer];

    //Determine suit
    CAShapeLayer *cardSuitShapeLayer;

    if ([suit isEqualToString:@"heart"]) {
        cardSuitShapeLayer = [CardElementsCreationClass drawHeart];
    }

    [front addSublayer:cardSuitShapeLayer];

    //Determine value
    CATextLayer *cardValueTextLayer = [CardElementsCreationClass drawValueWithSuit:suit AndValue:value];

    [front addSublayer:cardValueTextLayer];

    //Add layers to card
    [playingCard.layer addSublayer:front];

    NSLog(@"Type = %@", [playingCard class]);

    //Return - **ERROR HAPPENS HERE**
    return playingCard;
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    // Drawing code
    [CardCreationClass newPlayingCardWithSuit:@"heart" AndValue:@"A"];
}

@end

描画コード

#import "CardElementsCreationClass.h"

@implementation CardElementsCreationClass

//--------------------
//HEARTS
//
+ (CGMutablePathRef)newHeartPath {
    //Declare
    CGMutablePathRef heartPath = CGPathCreateMutable();

    //Create shape
    CGPathAddEllipseInRect(heartPath, NULL, CGRectMake(0, 0, 20, 20));
    CGPathAddEllipseInRect(heartPath, NULL, CGRectMake(20, 0, 20, 20));

    CGPathMoveToPoint(heartPath, NULL, 37.5, 16.5);

    CGPathAddLineToPoint(heartPath, NULL, 37.5, 16.5);
    CGPathAddLineToPoint(heartPath, NULL, 20, 37.5);
    CGPathAddLineToPoint(heartPath, NULL, 2.5, 16.5);
    CGPathAddLineToPoint(heartPath, NULL, 20, 10);

    CGPathCloseSubpath(heartPath);

    //Return
    return heartPath;
}

+ (CGMutablePathRef)newHeartHighlightPath {
    //Declare
    CGMutablePathRef heartHighlightPath = CGPathCreateMutable();

    //Create hightlight
    CGPathAddArc(heartHighlightPath, NULL, 0, 0, 7, -(110 * M_PI) / 180, -(0 * M_PI), NO);

    CGPathAddLineToPoint(heartHighlightPath, NULL, 4, 0);

    CGPathAddCurveToPoint(heartHighlightPath, NULL, 4, -7, 0, -7, 0, -7);

    //Return
    return heartHighlightPath;
}

+ (CAShapeLayer*)drawHeart {
    CAShapeLayer* heartShapeLayer = [CAShapeLayer layer];

    //Context
    CGContextRef context = UIGraphicsGetCurrentContext();

    //Declare
    CGMutablePathRef heartPath = [self newHeartPath];

    /*CGPathAddArc(heartPath, NULL, 10, 10, 10, M_PI, 0, false); // Left hump
    CGPathAddArc(heartPath, NULL, 30, 10, 10, M_PI, 0, false); // Right hump
    CGPathAddLineToPoint(heartPath, NULL, 20, 37.5); // Pointy end

    CGPathCloseSubpath(heartPath);*/

    //Line
    CGContextSetLineWidth(context, 8.0);
    CGContextSetLineJoin(context, kCGLineJoinRound);

    //Colour shape
    CGContextSetCMYKStrokeColor(context, 0.17, 1, 1, 0.07, 1);
    CGContextSetCMYKFillColor(context, 0.07, 1, 1, 0.01, 1);

    //Draw shape
    CGContextTranslateCTM(context, 4, 4);

    CGContextAddPath(context, heartPath);
    CGContextDrawPath(context, kCGPathStroke);

    CGContextAddPath(context, heartPath);
    CGContextDrawPath(context, kCGPathFill);

    //Colour highlight
    CGContextSetCMYKFillColor(context, 0, 0, 0, 0, 0.3);

    //Left highlight
    CGMutablePathRef heartHightlightLeft = [self newHeartHighlightPath];

    //Draw highlight
    CGContextTranslateCTM(context, 10, 9);

    CGContextAddPath(context, heartHightlightLeft);
    CGContextDrawPath(context, kCGPathFill);

    //Right highlight
    CGMutablePathRef heartHightlightRight = [self newHeartHighlightPath];

    //Draw hightlight
    CGContextTranslateCTM(context, 20, 0);

    CGContextAddPath(context, heartHightlightRight);
    CGContextDrawPath(context, kCGPathFill);

    //Attach
    heartShapeLayer.path = heartPath;

    //Release
    CGPathRelease(heartPath);
    CGPathRelease(heartHightlightLeft);
    CGPathRelease(heartHightlightRight);

    //Return
    return heartShapeLayer;
}

//--------------------
//VALUES
//
+ (CATextLayer*)drawValueWithSuit:(NSString *)suit
                         AndValue:(NSString *)value {
    CATextLayer* valueTextLayer = [CATextLayer layer];

    valueTextLayer.string = value;
    valueTextLayer.borderWidth = 2.0;
    valueTextLayer.borderColor = [UIColor blackColor].CGColor;

    valueTextLayer.bounds = CGRectMake(0, 0, 50, 50);

    //Determine colour
    if ([suit isEqualToString:@"heart"] || [suit isEqualToString:@"diamond"]) {
        valueTextLayer.foregroundColor = [UIColor redColor].CGColor;
    } else if ([suit isEqualToString:@"club"] || [suit isEqualToString:@"spade"]) {
        valueTextLayer.foregroundColor = [UIColor blackColor].CGColor;
    }

    //Return
    return valueTextLayer;
}

@end
4

1 に答える 1

2

メソッドの名前を変更するだけです

+ (UIView *) newPlayingCardWithSuit:(NSString *)suit
                           AndValue:(NSString *)value

単語で始まらないものにnew。例えば:

+ (UIView *) playingCardWithSuit:(NSString *)suit
                        andValue:(NSString *)value
于 2012-06-17T12:47:41.337 に答える