0

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?

???

1 Answers1

0

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:

  1. A View Controller method: [localMethod doSomethingWith:userSelectionFromPicker]
  2. NB: 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 dismissed
  3. A notification is invoked when userSelectionFromPicker changes
paul.lander
  • 458
  • 4
  • 5
  • How can I make it do something (action) when I select English and French? –  Dec 27 '11 at 20:58
  • How can I make it do something (action) when I select English and French? –  Dec 31 '11 at 11:55