简体   繁体   English

如何使用目标c匹配两个随机数,然后在xcode界面构建器中打印匹配项

[英]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.

相关问题 界面生成器/目标C问题 - Interface builder/Objective C problem MVC在Objective-C中开发而不使用Interface Builder - MVC when developing in objective-C without using the Interface Builder 如何在目标C中创建可重用的Web界面类? - How do I make a reusable web interface class in objective C? 如何在不使用“界面”构建器的情况下创建简单按钮? - How do I create a simple button without using the Interface builder? 如何使用Interface Builder将'M'放在MVC中 - How do I put the 'M' in MVC using Interface Builder 如何使用界面构建器将预定义的UITableView填充到视图中 - How do I populate a predefined UITableView to a view using the interface builder 如何设置用于显示数字的填充字符(目标C) - How do I set the fill character for displaying numbers (Objective C) 如何在xcode4的界面构建器中为视图设置辅助功能标签? - How do I set the accessibility label for a view in xcode4's interface builder? 最接近XCode,Windows上的Objective-C(非Hackintosh),也许是接口构建器 - Closest thing to XCode, Objective-C on Windows (Not Hackintosh), perhaps interface-builder 如何在Interface Builder中创建NSToggleButton? - How do I create a NSToggleButton in Interface Builder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM