- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 arc4random 创建一个测验来随机化我收到的问题。我想知道如何随机选择哪个答案出现在哪个按钮上。下面是一些代码 函数随机化(){
var RandomNumber = arc4random() % 4
RandomNumber += 1
switch (RandomNumber) {
case 1:
Question.text = "What greeting would you use in the morning"
Answer1.setTitle("Hello", forState: UIControlState.Normal)
Answer2.setTitle("Goodbye", forState: UIControlState.Normal)
Answer3.setTitle("Good Morning", forState: UIControlState.Normal)
Answer4.setTitle("See you soon", forState: UIControlState.Normal)
Answer5.setTitle("Ni Hao", forState: UIControlState.Normal)
Answer6.setTitle("CTA", forState: UIControlState.Normal)
CorrectAnswer = "1"
break
编辑:我想要的是所有问候出现在任何按钮上,但所有 6 个都出现在其中一个按钮上。
最佳答案
你可以试试下面的方法:
let Answer1 = UIButton()
let Answer2 = UIButton()
let Answer3 = UIButton()
let Answer4 = UIButton()
let Answer5 = UIButton()
let Answer6 = UIButton()
let buttons = [Answer1, Answer2, Answer3, Answer4, Answer5, Answer6]
var answers = [
"this is answer 1",
"this is answer 2",
"this is answer 3",
"this is answer 4",
"this is answer 5",
"this is answer 6"
]
for button in buttons {
let index = Int(arc4random_uniform(UInt32(answers.count)))
button.setTitle(answers[index], forState: .Normal)
answers.removeAtIndex(index)
}
println("Answer1 title: \(Answer1.titleForState(.Normal))")
println("Answer2 title: \(Answer2.titleForState(.Normal))")
println("Answer3 title: \(Answer3.titleForState(.Normal))")
println("Answer4 title: \(Answer4.titleForState(.Normal))")
println("Answer5 title: \(Answer5.titleForState(.Normal))")
println("Answer6 title: \(Answer6.titleForState(.Normal))")
关于ios - 如何快速随机化 button.setTitle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30024424/
我遇到过这个 html: 上面的html和这个有什么区别: 最佳答案 来自MDN page on the tag : 对于 type 的属性标签,可能的值是: 提交:按钮将表单数据提交给服务器
Button button= (Button) findViewbyID(R.id.button); 和 Button button = new Button(this); 有什么区别? 最佳答案 有
我是一名优秀的程序员,十分优秀!