gpt4 book ai didi

ios - 根据选择器选择确定Segue IOS,swift

转载 作者:可可西里 更新时间:2023-11-01 01:34:18 24 4
gpt4 key购买 nike

我目前有一个有两个选项的选择器,我正在寻找的是,根据在选择器中所做的选择,确定下面的下一个 viewController 是我尝试使用的,但是,我立即收到一个错误说明最后一个“if”语句应转换为 let 语句。下面是我的选择器的代码,并试图引导到相关的 segue。

import UIKit
import Firebase
import CoreData
import CoreLocation

class SchoolPickerViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var SchoolPicker: UIPickerView!
let pickerData = ["Ohio State University", "University of Rochester"]
override func viewDidLoad() {
super.viewDidLoad()
SchoolPicker.dataSource = self
SchoolPicker.delegate = self
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[row]
}

@IBAction func schoolSelectorGoButton(sender: AnyObject) {
if pickerData = "Ohio State University" {
performSegueWithIdentifier("ohioStateSelected", sender: sender)
}
if pickerData = "University of Rochester" {
performSegueWithIdentifier("rochesterSelected", sender: sender)
}
}


}

最佳答案

你应该从数组中获取选定的选择器数据

定义

var selectedIndex = 0

然后在这一行

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? 
{
selectedIndex = row
return pickerData[row]
}

在这个 Action 中

@IBAction func schoolSelectorGoButton(sender: AnyObject) {
if pickerData[selectedIndex] == "Ohio State University" {
performSegueWithIdentifier("ohioStateSelected", sender: sender)
}
}

关于ios - 根据选择器选择确定Segue IOS,swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38801223/

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