Matt Spoon
Matt Spoon

Reputation: 2830

Issue with contents of multiple pickerView's iOS swift

I am trying to place two picker views in one view controller. I have implemented both pickerView:viewForRow: and pickerView:titleForRow:. These functions use tags to differentiate between pickers. My problem is that only one of them will be effective. So, because I want views in one and text in the other, but it will be the case that either both get views or both get text. Can I use the pickerView:titleForRow: function on one and pickerView:viewForRow: for the other?

Upvotes: 0

Views: 91

Answers (1)

Paulw11
Paulw11

Reputation: 114783

Unfortunately you can't use both pickerView:viewForRow and pickerView:titleForRow at the same time in the same UIPickerViewDelegate. While pickerView:titleForRow returns String?, giving the option of returning nil, pickerView:viewForRow does not return an optional; if you implement this function then it must return a view.

This leaves you with two options:

  1. Create a suitable view for your 'string' picker - A UILabel, for example, and return it from pickerView:viewForRow
  2. Create a separate object to serve as the delegate for one of the picker views

Upvotes: 1

Related Questions