发送到 UILabel 的随机文本
我正在尝试创建一个包含 x 数量的文字字符串的数组,该数组会在您点击 UIButton 后随机发送一个到 UILabel。
我应该如何构建 .h 和 .m 文件来做到这一点?另外,生成我需要的随机数的最佳方法是什么?
I'm trying to create an array that holds x amount of literal strings that will randomly send one to a UILabel after you hit a UIButton.
How should I structure the .h and .m files to do this? Also, what is the best way to generate the random number I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将获得索引的随机整数,然后将获得的对象传递给 UILabel 的文本属性,例如:
您可以将上述代码放入按钮按下时调用的方法中。
编辑: 根据要求,这是一个简单的 Xcode 项目。
(注意:由于它是随机的,因此您有可能会得到相同的文本,因此可能看起来文本没有更改,但它确实更改为与之前您看不到的相同文本)
You would get a random integer for the index, and then just pass the object you get to the UILabel's text property, eg:
You'd put the above code in the method that the button calls when it's pressed.
EDIT: As requested here's a simple Xcode project.
(NOTE: As it's random there's a chance that you'll get the same text so it may appear that the text doesn't change, it does but it changes to the same text as before which you don't see)