2017-09-16 44 views
-1

我已將選取器視圖添加到我的應用程序並將其設置爲數字數組。當我運行應用程序時,所有我看到的都是問號。帶數字顯示問號的swift選取器視圖

有誰知道問題是什麼?我也嘗試使用類型Int並收到相同的結果。

這是我的代碼。

import UIKit 
import Firebase 
import FirebaseDatabase 
import FirebaseStorage 

class myViewController: UIViewController, UIPickerViewDelegate,UIPickerViewDataSource { 
    @IBOutlet weak var settings: UIBarButtonItem! 
    @IBOutlet weak var myTextField: UITextField! 
    @IBOutlet weak var enterExit: UISegmentedControl! 

    @IBOutlet weak var dayLabel: UILabel! 
    @IBOutlet weak var pickerView: UIPickerView! 
    @IBOutlet weak var daysTextField: UITextField! 

    let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14] 
    var hhh = Int() 
    let seconds = 60.0 

    func numberOfComponents(in pickerView: UIPickerView) -> Int { 
     return 1 
    } 

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

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
     return numbers.count 
    } 

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
     var days = numbers[row] 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.pickerView.delegate = self 
     self.pickerView.dataSource = self 

enter image description here

+0

檢查:HTTPS://stackoverflow.com/questions/40199826/uipickerviewdelegate-xcode-8-swift-3,我認爲你需要了解'uipickerviewdelegate'和'uipickerviewdatasource' – 3stud1ant3

+0

與更新你的問題您的相關代碼。顯示選取器視圖的委託和數據源方法。 – rmaddy

+0

有我的代碼@ 3stud1ant3 –

回答

2

你的問題是與以下幾點:

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

這種方法不應該是私有的,它應該有適當的簽名。此代表方法需要返回可選String,而不是可選Int

private func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
    return String(numbers[row]) 
} 
相關問題