根据按下的按钮,我想将单词列表附加到在开始时声明的变量(pickedList)。当我准备继续时,它会覆盖已添加的内容,并且仅使用开始时添加的空数组。我可以在准备继续位中添加项目并将这些项目转移过来,但这不是我想要的。我对编程非常陌生,并且进行了很多搜索,但似乎找不到我要找的东西。提前致谢!
代码如下所示:
类 activeLiteracyOptionsViewController: UIViewController {
@IBOutlet weak var satpinButton: UIButton!
var pickedList = [String]()
@IBAction func whenSatpinButtonPressed(sender: AnyObject) {
pickedList += ["s","a","t","p","i","n"]
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destinationViewController : flashcardsViewController = segue.destinationViewController as flashcardsViewController
destinationViewController.listToPlay = pickedList
我从没有以编程方式执行转场的情况推断出您必须同时设置IBAction
以及 Interface Builder 中按钮的转场。问题是segue(和prepareForSegue
)可以被称为before the IBAction
叫做。您应该删除该转场,并创建一个新的转场,您可以从IBAction
.
Therefore, you should not have the segue attached to the button in Interface Builder, but rather only have the button hooked up to the IBAction
. You can then define a segue between the two scenes controller by control-dragging from the view controller button in the bar above the source scene to the destination scene:
在场景之间添加此 Segue(但不是从源场景中的按钮)后,您现在可以在 Interface Builder 中选择该 Segue,转到属性检查器,并为该 Segue 提供唯一的“故事板标识符”:
如果你给它一个标识符SegueToSecondScene
,您现在可以定义您的IBAction
to set pickedList
然后以编程方式执行segue:
@IBAction func whenSatpinButtonPressed(sender: AnyObject) {
pickedList += ["s","a","t","p","i","n"]
performSegueWithIdentifier("SegueToSecondScene", sender: self)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)