我有以下代码。没有错误。应用程序崩溃。不确定我是否正确初始化。请,非常感谢任何帮助。
@IBOutlet weak var myCostPicker: UIPickerView!
var costCode = String()
override func viewDidLoad() {
super.viewDidLoad()
if let projectNum = projectNum {
projectNumTitle.title = projectNum
}
updateLabels()
myCostPicker.dataSource = self
myCostPicker.delegate = self
myCostPicker.showsSelectionIndicator = true
self.view.backgroundColor = UIColor.blackColor()
}
let pickerData = ["Nothing", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q"]
let costCodeData = ["Nothing", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q"]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
// MARK: - Picker Delegates
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String {
return pickerData[row]
}
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = pickerData[row]
var myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 15.0)!,NSForegroundColorAttributeName:UIColor.whiteColor()])
return myTitle
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
myLabel.text = pickerData[row]
costCode = costCodeData[row]
}
达到了心理障碍。需要有人来敲打我的脑袋。赞赏。