I don't understand which outlets should be connected! In outlets i have:
dataSource
delegate
But where should i connect them? And how can i then use them?
???
I don't understand which outlets should be connected! In outlets i have:
dataSource
delegate
But where should i connect them? And how can i then use them?
???
In Xcode, connect the datasource & delegate outlets to the UIViewController that contains the UIPickerView. The datasource methods are declared in the UIViewController implementation. Let's say your picker will display: "English" and "French":
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSArray *pickerContent = [NSArray arrayWithObjects:@"English", @"French", nil];
return [pickerContent objectAtIndex:row];
}
The delegate methods are also declared in the UIViewController implementation:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSArray *titles = [NSArray arrayWithObjects:@"English", @"French", nil];
NSString *userSelectionFromPicker = [titles objectAtIndex:row];
}
Some examples of how userSelectionFromPicker
can be used to perform an action in the app:
[localMethod doSomethingWith:userSelectionFromPicker]
userSelectionFromPicker
is made a property of the View Controller (as opposed to a local variable) and accessed by the View Controller's delegate - often when the View Controller is dismisseduserSelectionFromPicker
changes