How to initialize UiPickerView inside custom tableViewCell?

后端 未结 1 443
太阳男子
太阳男子 2021-01-16 09:36

I am trying to create PickerView inside tableViewCell. I made my custom cell conform UIPickerViewDelegate and UIPickerViewDataSo

1条回答
  •  囚心锁ツ
    2021-01-16 10:34

    Your issue is that you have reload the components of PickerView so make one small change in your cellForRowAtIndexPath and just reload the components of PickerView after setting the pickerData Array.

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> 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
        cell.picker.reloadAllComponents();
        return cell
    }
    

    Also in awakeFromNib initialize your pickerData object

    override func awakeFromNib() {
        self.pickerData = Array()
        self.picker.delegate = self;
        self.picker.dataSource = self;
        super.awakeFromNib()
    
    }
    

    0 讨论(0)
提交回复
热议问题