How to initialize UiPickerView inside custom tableViewCell?
<p>I am trying to create <code>PickerView</code> inside <code>tableViewCell</code>. I made my custom cell conform <code>UIPickerViewDelegate</code> and <code>UIPickerViewDataSource</code> protocols. I send data array to cell from the controller (I think this doesn't conform to MVC pattern, may be you also can suggest me how to fix that?). But when tableview calls <code>dequeueReusableCellWithIdentifier</code> the cell calls pickerView function. However, pickerView function uses <em>pickerData</em> which is not initialized yet. How do I fix that? </p>

<p>Below is my code for the cell:</p>

<pre><code>class PickerTableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var picker: UIPickerView!
    @IBOutlet weak var title: UILabel!
    var pickerData: Array&lt;String&gt;!
    override func awakeFromNib() {
        self.picker.delegate = self;
        self.picker.dataSource = self;
        super.awakeFromNib()

    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
        return pickerData.count // I get fatal error here due to pickerData is nil
    }

    func numberOfComponentsInPickerView(pickerView: UIPickerView) -&gt; Int {
        return 1
    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String? {
        return pickerData[row]
    }


}
</code></pre>

<p>And here is the code for the cell's initialization:</p>

<pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("picker", forIndexPath: indexPath) as! PickerTableViewCell
    cell.title.text = fieldModel.editFieldArray[indexPath.row].title
    cell.pickerData = (fieldModel.editFieldArray[indexPath.row] as! PickerEditField).pickerData
    return cell
}
</code></pre>

<p>Thanks a lot for any help!</p>