Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom number to pick an image Xcode iPhone
    text
    copied!<p>I've been searching all over the net for an answer to this one! Hoping one of you can help me.</p> <p>So far I have a button that produces a random nr between 1 and 6 in a label.</p> <blockquote> <blockquote> <p>Then I want a picture to appear depending on what nr is in the label.</p> </blockquote> </blockquote> <p>For example: If the number 1 is generated, I want img1.png to appear in a UIImageView.(?) I'm thinking maybe a if function to pick the picture? </p> <p>Sorry for bad formating.</p> <p>Here is the .h file:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface xxxViewController : UIViewController { IBOutlet UILabel *label; int randomNumber; } -(IBAction)randomize; @end </code></pre> <p>...and here is the .m file:</p> <pre><code>#import "xxxViewController.h" @implementation xxxViewController -(IBAction)randomize { int randomNumber = 1+ arc4random() %(6); label .text = [NSString stringWithFormat:@"%d",randomNumber]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; int randomNumber = 1+ arc4random() %(6); label .text = [NSString stringWithFormat:@"%d",randomNumber]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload