ios Xcode8 - 无法查看选择器上的列表

时间:2017-06-05 17:07:08

标签: xcode8 uipickerview

新手在这里。我正在尝试创建一个具有多个选择器的视图控制器。然而,就目前的形式而言,我看不到任何拣货员的名单。此外,只有第一个选择器似乎可以工作,并且只在#34; var country"下取第一个值。其他人没有回应。任何人都可以看到问题吗?

import UIKit

class ViewController: UIViewController,UIPickerViewDelegate, UIPickerViewDataSource {


@IBOutlet weak var countrytxt: UITextField!

@IBOutlet weak var vitestxt: UITextField!

@IBOutlet weak var yakittxt: UITextField!

@IBOutlet weak var motorgucutxt: UITextField!

var country = ["1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998","1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019"]

var vites = ["Manuel", "Otomatik", "Yarı Otomatik"]

var yakit = ["Benzin", "Dizel", "LPG", "Hybrid", "Elektrik"]

var motorgucu = ["1.0", "1.2", "1.4", "1.6", "1.8", "2.0", "2.2", "2.4" ]

let picker = UIPickerView()

override func viewDidLoad() 
{
super.viewDidLoad()
picker.delegate = self
picker.dataSource = self
countrytxt.inputView = picker
countrytxt.inputView = picker
vitestxt.inputView = picker
yakittxt.inputView = picker
motorgucutxt.inputView = picker
}

public func numberOfComponents(in pickerView: UIPickerView) -> Int
{
return 1
}
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
if picker == countrytxt
{
return country.count
}
else if picker == vitestxt
{
return vites.count
}
else if picker == yakittxt
{
return yakit.count
}
else if picker == motorgucutxt
{
return motorgucu.count
}
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{

if picker == countrytxt
{
return country[row]
}
else if picker == vitestxt
{
return vites[row]
}
else if picker == yakittxt
{
return yakit[row]
}
else if picker == motorgucutxt
{
return motorgucu[row]
}
return " "
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
countrytxt.text = country[row]
self.view.endEditing(false)
}
}

0 个答案:

没有答案