[英]How do I match two random numbers, then print match in xcode interface builder, using objective c
I am trying my first iphone app. 我正在尝试我的第一个iPhone应用程序。 I am stuck now.
我现在被困住了。 I have two label that display seperate random numbers.
我有两个标签显示单独的随机数。 I used a button and IBAction to generate the numbers then pass them to the label.
我使用了一个按钮和IBAction来生成数字,然后将其传递给标签。 Now I need to determine when the two numbers match and then print "match" in another label.
现在,我需要确定两个数字何时匹配,然后在另一个标签中打印“匹配”。 I am trying all kinds of different things but somehow I am missing something.
我正在尝试各种不同的东西,但是以某种方式我缺少了一些东西。 If anyone can help explain how to do this form a code point of view and hooking it into interface builder that would be awesome!
如果有人可以帮助解释如何从代码角度将其完成,并将其挂接到界面构建器中,那将非常棒! Thanks
谢谢
In the method where you get and show the random numbers you simply compare them and change the text in the third label accordingly. 在获取并显示随机数的方法中,您只需将它们进行比较,然后相应地更改第三个标签中的文本。
- (IBAction)buttonPressed {
// Generate the 2 random numbers and show them in the labels here.
// Then compare them and show the result in the third label:
if (randomNumber1 == randomNumber2) {
thirdLabel.text = @"Match";
} else {
thirdLabel.text = @"No Match";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.