0

我有一个使用我想要的值的 iOS UiPicker,并且可以使用以下代码检测何时选择了新选项:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSString *aCompany = [arrayColour objectAtIndex:[pickerView selectedRowInComponent:0]];

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Picked:"
                          message:aCompany
                          delegate:nil
                          cancelButtonTitle:@"Okay"
                          otherButtonTitles:nil];

    [alert show];


}

我的问题是如何在按下这样的按钮后从选择器中获取最新信息:

- (IBAction)DoneButton:(id)sender {



    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Picked:"
                          message:aCompany
                          delegate:nil
                          cancelButtonTitle:@"Okay"
                          otherButtonTitles:nil];

    [alert show];

}
4

1 回答 1

2

将您的设置pickerViewIBOutlet(并使用 IB 链接),然后您可以在didSelectRow.

@property (nonatomic) IBOutlet UIPickerView *myPickerView;

然后您可以在中使用以下行DoneButton

NSString *aCompany = [arrayColour objectAtIndex:[self.myPickerView selectedRowInComponent:0]];
于 2013-04-23T22:22:12.840 回答