次のコードがあります。エラーは発生しません。アプリがクラッシュします。正しく初期化されたかどうかわかりません。どうぞ、どんな助けでも大歓迎です。
@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]
}
メンタルブロックに到達。私のノギンを瓶詰めする人が必要です。感謝。