mercredi 5 août 2015

UIPickerView showing empty grey box Swift


I haven't a whole lot of code, so I might as well copy it here.

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource{

    var buildings = ["BankBuilding", "Cinema" , "CornerShop", "Greg's House"]

    @IBOutlet weak var buildText: UITextField!

    var buildPickers:UIPickerView = UIPickerView()

    override func viewDidLoad() {
        super.viewDidLoad()

        buildPickers = UIPickerView()
        buildPickers.delegate = self
        buildPickers.hidden = true;
        buildText.inputView = buildPickers
        buildText.text = buildings[0]        
    }

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

    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
        println("Count: \(buildings.count)")
        return buildings.count
    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
        println("creating title: \(buildings[row])")
        return buildings[row]
    }

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
    {
        println("Selected: \(buildings[row])")
        buildText.text = buildings[row]
        buildPickers.hidden = true;
    }

    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        buildPickers.hidden = false
        return false
    }
}

The print statements are correct. For numberOfRows... and titleForRow it is printing the correct Strings.

But there is no prints for didSelectRow because, well, I can't select a row.

This is what I get:

enter image description here

You can ignore the Google Map in the background, that shouldn't interfere with the Picker View and is just set up in the StoryBoard.

The Grey window appears when I click on the textField but never shows any content. But the print statements say otherwise.

Does anyone know why this is the case?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire