Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
random number & reading verifying from memory or string
I wanted to make a test, with 2 buttons & 1 label, 1 button generate an random number then sends that number to UILabel. But how do I read what either that random generated number is in memory, or what the value of the UILabel is? ... cause I wanted to make an button that gives a smiley if the number is 22 - just for practise purposes...
might be a stupid question but have you set label.text to 1 too? have you linked "label" in IB or did you initialize it somewhere previous?
label is declared in the header & synthesized in the implementation file. It is not intialized pre that it gets it value from the int, that generates a random number
but you have to either declare your UILabel as IBOutlet and link it with the appropriate label in IB (so it gets initialized automatically) or initialize it manually and add it as subview. you can't set an attribute of an object that does not exist
now it has outputed the random value that is between 1 and 10 to the label.
that's actually wrong, it's a value between 0 and 9. if you want a value between 1 and 10 you have to say
Replies
- (IBAction)Gen:(UIButton *)sender {
int generate = arc4random() & 150;
[label setText : [NSString stringWithFormat : @\" %i\", generate]];
}
- (IBAction)seed:(UIButton *)sender {
if ([label.text isEqualToString:@\"22\"]){
[label2 setText : [NSString stringWithFormat : @\":)!\"]];
}
else {
[label2 setText : [NSString stringWithFormat : @\":(\"]];
}
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethe text property is what you need. just make sure you use isEqualToString: instead of just == tho
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomehave you linked "label" in IB or did you initialize it somewhere previous?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomenow it has outputed the random value that is between 1 and 10 to the label.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeyou can't set an attribute of an object that does not exist that's actually wrong, it's a value between 0 and 9. if you want a value between 1 and 10 you have to say
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome