I am new to iOS programming.
I am getting an "Incompatible integer to pointer conversion sending 'int' to parameter of type 'NSString *'" error when I try and run the following code:
- (IBAction)oneToSix {
int rNumber = arc4random() % 6;
[result setImage:[UIImage imageNamed: rNumber]];
}
You need to convert the int to a NSString before sending it to the imageNamed method. This is because imageNamed takes a NSString as the argument and not an int. Try this:
- (IBAction)oneToSix {
int rNumber = arc4random() % 6;
[result setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d", rNumber]]];
}
More info here: UIImage Class Reference.
The problem is that imageNamed: takes an NSString as input, not an int. To fix this, just convert the int into an NSString by
[NSString stringWithFormat:@"%d",rNumber]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With