ios - 如何将分段控制变量发送到prepareforsegue?

标签 ios swift

如何确保将 selectedFocus 发送到 prepareForSeque 中的下一个 View Controller ? (或根据 prepareForSeque 中分段控制按钮的哪一部分分配变量?)“Use of unresolved identifier 'segmentedControlVariable” 是我的错误。

class SecondSignUpViewController: UIViewController {

    // DECLARATIONS...

    // user's focus to be sent to next view contr.
    var selectedFocus = String()

    // 1. LOAD IN SENT VARS (so that it exists in this view) (at top it seems oposed to in viewdidload?...)
    var passedPassword_toView2:String!
    var passedUsername_toView2:String!
    var passedEmail_toView2:String!

    @IBAction func continueButtonPressed2(sender: AnyObject) {
        performSegueWithIdentifier("SegueAfterJoin2", sender: self)
    }



@IBAction func indexChanged(sender: AnyObject) {
    switch segmentedControl.selectedSegmentIndex {
    case 0:
        print("case0")
        textLabel.text = "You are a music artist who needs services.";
        imageShown.image = image0
        selectedFocus = "artist"
    case 1:
        print("case1")
        textLabel.text = "You want to share your talent with music artists.";
        imageShown.image = image1
        selectedFocus = "provider"
    default:
        break; 
    }
}

// VAR SHIFT 
// GET FROM PREV. VIEW
override func viewDidLoad() {
    super.viewDidLoad()
    print("view 2 loaded")

    // 2. (for ease,) TRANSFER TO VAR NAMES
    var myLocalPassword = passedPassword_toView2
    var myLocalUsername = passedUsername_toView2
    var myLocalEmail = passedEmail_toView2

}

// 3. SEND VARS TO NEW VIEW
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "SegueAfterJoin2") {
        var nextViewCont = segue!.destinationViewController as! ThirdSignUpViewController;

        // PASS VARS FROM THIS VIEW TO NEXT
        nextViewCont.passedPassword_toView3 = passedPassword_toView2
        nextViewCont.passedEmail_toView3 = passedUsername_toView2
        nextViewCont.passedUsername_toView3 = passedEmail_toView2

        //how can I toss this in too?
        nextViewCont.passedFocus_toView3 = selectedfocus

    }
}

最佳答案

在你的 thirdviewcontroller 上你创建了 passedFocus_toView3 变量

喜欢

在你的第一个 View Controller 上调用这个

   override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "YourSegueName") {
        //get a reference to the destination view controller
        let destinationVC:ViewControllerClass = segue.destinationViewController as! ViewControllerClass

        //set properties on the destination view controller
        destinationVC.passedFocus_toView3 = selectedfocus
        //etc...
    }
}

关于ios - 如何将分段控制变量发送到prepareforsegue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36148072/

相关文章:

ios - FMDB - 错误调用 sqlite3_step (21 : out of memory) rs

iphone - 确定 iPad 上 UITableView 的大小

swift - CGAffineTransform 连接两个矩阵与将一个矩阵应用于另一个矩阵

ios - 将存储为 NSdata 的图像放入 pickerView 时发生错误

swift - 如何在 swift 4 中调用单独的函数文件

iphone - 如何检查 map 上的重复注释

ios - 单击时更改单元格中的按钮颜色

ios - NSDateFormatter - setLocale 被忽略?

ios - 对于 alertController : what is the sourceView of a selected segment in a UISegmentedControl

swift - SKEmitterNode 崩溃