显示上的一个按钮阵列的内容,使用标签 [英] Showing array content on a button, using a label

查看:63
本文介绍了显示上的一个按钮阵列的内容,使用标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索周围,但没有找到答案。这可能是简单的,但我也没有弄清楚你是如何suposed做到这一点。所以......

我想要一个按钮显示在标签上的数组。当我preSS的第一次中,标签显示阵列中的第一个数字,一个pressing的第二时间使标签打印所述第二编号的数组中

  VAR primeString =60,52,81,61,85]
@IBOutlet VAR PrimeLabel:的UILabel!@IBAction FUNC NewAction(发件人:AnyObject){
    //这里是我想要的标签显示的顺序排列,当我preSS它。
}


解决方案

所以才得到这个连败。每次preSS的按钮时,您希望通过标签数组中的显示下一个元素。好吧,这应该是相当简单。像下面的东西会为你做的。

  VAR primeString =60,52,81,61,85]
VAR currentElement = 0@IBOutlet VAR PrimeLabel:的UILabel!@IBAction FUNC NewAction(发件人:AnyObject){
   如果currentElement< primeString.count {
      PrimeLabel.text = primeString [currentElement]
      currentElement ++
   }其他{
      打印(没有更多的元素,以显示。)
   }
}

没有必要有观点做了负载,因为我们不需要做任何设置,一旦视图已经加载。我希望这可以帮助你。

I have searched around but have not found an answer. It may be simple but I can nor figure out how you are suposed to do it. So...

I want a button to show an array on a label. When I press the first time, the label show the first number in the array, an pressing a second time makes the label print the second number in the array.

var primeString = ["60","52","81","61","85"]
@IBOutlet var PrimeLabel: UILabel!

@IBAction func NewAction(sender: AnyObject) {
    // Here is where I want to make the label show the array in the order when I press it.
}

解决方案

So just to get this straight. Each time you press the button you want to display the next element in the array through the label. Okay, that should be fairly simple. Something like below will do that for you.

var primeString = ["60","52","81","61","85"]
var currentElement = 0

@IBOutlet var PrimeLabel: UILabel!

@IBAction func NewAction(sender: AnyObject) {
   if currentElement < primeString.count {
      PrimeLabel.text = primeString[currentElement]
      currentElement++
   } else {
      print("No more elements to display.")
   }
}

No need to have the view did load, as we don't need to do any setup once the view has loaded. I hope this helps you out.

这篇关于显示上的一个按钮阵列的内容,使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆