本文介绍了当SEGUE阵列preparing不包含数据(使用SWIFT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据什么按钮pssed欲单词列表追加到变量(pickedList)$ P $在开始声明。当我来到prepare为赛格瑞它将覆盖什么已经被添加,只采用在开始时加入空数组。我能够通过追加prepare内物品赛格瑞位和这些转移,但这不是我想要的。我非常非常新的节目,并搜查了很多,但似乎无法找到我所期待的。在此先感谢!

code是这样的:

类activeLiteracyOptionsViewController:UIViewController的{

  @IBOutlet弱VAR satpinButton:UIButton的!
VAR pickedList = [字符串]()@IBAction FUNC whenSatpinButton pressed(发件人:AnyObject){    pickedList + = [S,一个,T,P,我,N]
}覆盖FUNC prepareForSegue(SEGUE:UIStoryboardSegue,发件人:AnyObject?){   让destinationViewController:flashcardsViewController = segue.destinationViewController为flashcardsViewController   destinationViewController.listToPlay = pickedList


解决方案

我从没有编程,你必须设置既是 IBAction为作为执行SEGUE的推断以及从在Interface Builder的按钮SEGUE。问题是,赛格瑞(和 prepareForSegue )可称为的的在 IBAction为被调用。您应该删除SEGUE,并创建一个新的,你会编程方式从调用 IBAction为

所以,你不应该有附加到界面生成器的按钮SEGUE,而是只挂在 IBAction为按钮。然后,您可以定义控制两个场景控制器之间的SEGUE 在源场景到目的地现场上方的栏从视图控制器按钮-dragging:

已经添加了这个赛格瑞的场景之间(而不是从源场景中的按钮),你现在可以选择在Interface Builder是SEGUE,进入属性检查器中,并给予Segue公司独特的故事板标识:

如果你给它 SegueToSecondScene 的标识符,你现在可以定义你的 IBAction为设置 pickedList ,然后以编程执行SEGUE:

  @IBAction FUNC whenSatpinButton pressed(发件人:AnyObject){
    pickedList + = [S,一个,T,P,我,N]
    performSegueWithIdentifier(SegueToSecondScene,发件人:个体经营)
}

Depending on what button is pressed I want to append a list of words to variable (pickedList) declared at the start. When I come to prepare for segue it overwrites what has been added and only using empty array that was added at the start. I am able to append items within the prepare for segue bit and these transfer over but this is not what I want. I am very very new to programming and have searched about a lot but can't seem to find what I am looking for. Thanks in advance!

Code looks like this:

class 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
解决方案

I infer from the absence of performing the segue programmatically that you must have set up both an IBAction as well as a segue from the button in Interface Builder. The problem is that the segue (and prepareForSegue) may be called before the IBAction is called. You should remove that segue, and create a new one that you'll invoke programmatically from the 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 -dragging from the view controller button in the bar above the source scene to the destination scene:

Having added this segue between the scenes (but not from the button within the source scene), you can now select that segue in Interface Builder, go to the attributes inspector, and give that segue a unique "storyboard identifier":

If you gave it an identifier of SegueToSecondScene, you can now define your IBAction to set pickedList and then programmatically perform the segue:

@IBAction func whenSatpinButtonPressed(sender: AnyObject) {
    pickedList += ["s","a","t","p","i","n"]      
    performSegueWithIdentifier("SegueToSecondScene", sender: self)
}

这篇关于当SEGUE阵列preparing不包含数据(使用SWIFT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:48