简体   繁体   中英

Empty UIPickerView in second view controller

I have problem with a picker view that appears empty when I make it in second view controller.(image1).

When I make it in the first view controller that work fine. two view controller and pickerview

code:

import UIKit

class ViewController: UIViewController, UIPickerViewDelegate {
    var civilite = ["Madame","Monsieur","Mademoiselle"]

    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return civilite.count
    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!{
        return civilite[row]
    }

}

Xcode 6.4

I found the solution.

I add new file "Cocoa touch class" (Formulaire.swift)
I change the custom class of the second view controller to be "Formulaire" [Custom class][1] [1]: http://i.stack.imgur.com/H4Nip.png
I deplace the code in this file and is work fine. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM