How do I program the Storyboard Segue?

Asked 2 years ago, Updated 2 years ago, 138 views

In Xcode 7 (Swift), install PickerView (two items) and place the transition button under the part.
If you select two things in PickerView, it will be displayed on the label, and if you press the button under the part, it will transition to the detail page of the contents displayed on the label.

 var myUIPicker:UIPickerView=UIPickerView()
var large —NSArray=["A", "B", "C", "D" ]
var country: NSAray=["World", "America", "China", "Japan", "India", "UK" ]

@IBOutlet weak var myLabelFst: UILabel!
@IBOutlet weak var myLabelSec: UILabel!
@IBOutlet weak var myPicker:UIPickerView!
override func viewDidLoad(){
    super.viewDidLoad()



    myUIPicker.frame = CGRectMake(0,120,self.view.bounds.width, 180.0)
    myUIPicker.delegate=self
    myUIPicker.dataSource=self
    self.view.addSubview(myUIPicker)


    // Do any additional setup after loading the view.
}

func numberOfComponentsInPickerView (pickerView:UIPickerView) - > Int {
    return2
}

funcpickerView (pickerView:UIPickerView, numberOfRowsInComponent component:Int) - > Int {
    if component == 0 {
        return large.count
    } else if component == 1 {
        return country.count
    }
    return 0;
}

funcpickerView (pickerView:UIPickerView, titleForRow:Int, forComponent component:Int) - > String?{
    if component == 0 {
        return large [row] as ? String
    } else if component == 1 {
        return country [row] as ? String
    }
    return '';
}

funcpickerView(pickerView:UIPickerView, didSelectRowrow:Int, inComponent component:Int){
    if component == 0 {
        myLabelFst.text=
        ("\(large[row]")"
    } else if component == 1 {
       myLabelSec.text=
        ("\(country[row]")
    }
}

@ IBAction func showResult (sender: AnyObject) {
}

"From here, for example, to the ""A x Japan"" screen."

as shown on the "C×World" screen I would like to transition to the screen of each selected item, but
I don't know what kind of code to use.
I've looked it up, but I don't really understand how to do screen transitions in a multi-item pickerview.

If there is not enough information, I will add the missing parts as much as possible, thank you.
Also, I would appreciate it if you could let me know something like a hint.

Thank you for your cooperation.

ios swift xcode iphone uipickerview

2022-09-30 21:10

1 Answers

As for screen transitions, it is very convenient that you can handle them without writing the program code by pulling the Segue from controls such as buttons on the Storyboard to the View Controller of the transition destination.However, if you want to dynamically change the transition destination View Controller depending on the table view or picker view selection line, you still have to write some code.Then, what kind of work should I do specifically?
First, pull the Segue from the button to fix the transition destination, so pull the Segue from the View Controller, not from the button.

Enter a description of the image here

Then select the completed Segue to view Attributes Inspector.

Enter a description of the image here

Add an ID (Identifier) to the Segue.

Enter a description of the image here

Perform this task as many View Controllers as you want to transition to.
Then write a program to perform the screen transition. The performSegueWithIdentifier method means to execute a segment with an ID.The argument sender may be appropriate, but may have meaning, depending on the program configuration.

@IBAction func showResult (sender:AnyObject){
    performSegueWithIdentifier("AA", sender:self)
}

"AA" is the ID of the Segue.You can change this "AA" dynamically according to the picker view selection line to integrate with the picker view and transition.
It is recommended that you make a list of Segue identifiers and manage the transition destinations.I think there are many ways to manage it.Now let's use an array (Array).
"Let's say ""AJ"" is the ID of the Segue of the transition destination ""A×Japan"" screen."The same applies to other IDs.

let segmentIDarray: [[String]]=[[[AW", "AA", "AC", "AJ", "AI", "AU",
["BW", "BA", "BC", "BJ", "BI", "BU"],
["CW", "CA", "CC", "CJ", "CI", "CU",
["DW", "DA", "DC", "DJ", "DI", "DU"]

[String] is the type that represents the array of strings, and [[String]] is the type that represents an array of strings.It's called a two-dimensional array.You can now substitute the large index large and the country index to retrieve the element (the ID of the segment) in segueIDarray [large][country].


2022-09-30 21:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.