[英]How do I match two random numbers, then print match in xcode interface builder, using objective c
我正在嘗試我的第一個iPhone應用程序。 我現在被困住了。 我有兩個標簽顯示單獨的隨機數。 我使用了一個按鈕和IBAction來生成數字,然后將其傳遞給標簽。 現在,我需要確定兩個數字何時匹配,然后在另一個標簽中打印“匹配”。 我正在嘗試各種不同的東西,但是以某種方式我缺少了一些東西。 如果有人可以幫助解釋如何從代碼角度將其完成,並將其掛接到界面構建器中,那將非常棒! 謝謝
在獲取並顯示隨機數的方法中,您只需將它們進行比較,然后相應地更改第三個標簽中的文本。
- (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.