Reputation: 173
I am following a tutorial on lynda on basic Swift with Xcode. Now we have a code that uses Picker view with custom data. The idea is pretty simple, add data to that spinning wheel but I have difficulty reading methods in this protocol. There is this one - pickerView:titleForRow:forComponent:
I wonder how it gets a row value. By spinning wheel with finger or?? A code for this method goes like this:
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return moodArray[row]
}
Upvotes: 1
Views: 333
Reputation: 17378
The picker view is asking its delegate a question. "For the row and column(component) at index x what should my title be? Send me a String to let me know"
It's up to you to return a string from your moods array. Happy, Sad, Truculent , Confused . It's up to you.
Delegate methods are used so that to create a UI component there is no need to subclass objects. Literally you delegate work to an outside contractor.
Upvotes: 3