I want a button to change a label's text in a set series. For example, that one box app on the app store where theres a button and every time you press it, it says the next thing. I want, let's say, one button and one label. The first time you press the button, it says, "hi", you press it again and it says, "how", then, "are", "you?". How would I go about doing this? Any help would be good.
1 回答
1
向视图控制器添加一个整数属性
currentWordIndex,以记住哪个是当前单词。创建一个标签。将其连接到视图控制器中的插座,名称如
wordLabel.创建一个按钮。将其连接到将标签更改为您想要的任何文本的操作,如下所示:
- (IBAction)changeTheLabel:(id)sender
{
NSArray *words = @[@"hi", @"how", @"are", @"you?];
self.currentWordIndex = (self.currentWordIndex + 1) % [字数];
self.wordLabel.text = [words objectAtIndex:self.currentWordCount];
}
就这些。
于 2012-10-25T19:19:29.787 回答