gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:07:43 24 4
gpt4 key购买 nike

如何确保将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com