Je reçois l'erreur ci-dessus et je ne suis pas sûr de savoir comment résoudre ce problème, est-ce que quelqu'un pourrait me dire pourquoi je reçois cette erreur afin que je puisse le réparer?Types de pointeurs incompatibles renvoyant 'UIView * _strong' d'une fonction avec le type de résultat 'CardCreationClass *'
Le code lui-même fonctionne et dessine l'image (à l'exception de la couche de texte) à l'écran, donc je veux juste supprimer l'erreur. J'ai déjà cherché le débordement de la pile et j'ai trouvé 'casting' mais après avoir essayé cette technique, l'erreur est toujours là.
Je pense que c'est parce que je suis en utilisant les méthodes
[CardElementsCreationClass drawHeart]
et
[CardElementsCreationClass drawValueWithSuit:suit AndValue:value]
Mon .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
Code Dessin
#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
s'il vous plaît poster le code pour drawValueWithSuit et drawHeart –
Chaque fois que vous avez une question sur une erreur, s'il vous plaît montrer où l'erreur se produit. –
Veuillez poster le code qui appelle les méthodes. – Linuxios