문제

Specifically the warning is: "Incompatible Objective-C types 'struct NSString *', expected 'struct UIImage *' when passing argument 4 of 'objectWithType:name:code:image' from distinct Objective-C type". It follows a line that looks like so:

[Object objectWithType:@"Type" name:@"Name" code:@"0001" image:@"image.png"],

So, I understand that I created the class Object to take type UIImage, but I am providing it with type NSString. Here's the problem: I don't know how to indicate the image differently than its file name.

(Apologies if this is a basic problem. I'm new to this and trying to look for solutions before posting here. Any help you can offer is appreciated.)

도움이 되었습니까?

해결책

You actually need an instance of UIImage, which you understand. So, the class method imageNamed: is typically used for this:

[Object objectWithType:@"Type" name:@"Name" code:@"0001" image:[UIImage imageNamed:@"image.png"]];

Another option (since you are using all strings here) might be to rewrite your method so that it takes a name instead of an image and then create the image inside the method implementation. So you might define the method:

- (void)objectWithType:(NSString*)type name:(NSString*)name code:(NSString*)code imageName:(NSString*)imageName
{
  UIImage* theImage = [UIImage imageNamed:imageName];
  // do whatever
}

다른 팁

Use [UIImage imageNamed:]. Will only work for images that are part of your project.

[Object objectWithType:@"Type" name:@"Name" code:@"0001" image:[UIImage imageNamed:@"image.png"]]

If 'image.png' is included in your project bundle, then you can do this to pass a UIImage instead of an NSString:

[Object objectWithType:@"Type" name:@"Name" code:@"0001" image:[UIImage imageNamed:@"image.png"]];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top