按下IBAction后确定PickerView值

时间:2013-04-23 22:12:46

标签: iphone ios uipickerview

我有一个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];

}

1 个答案:

答案 0 :(得分:2)

pickerView设置为IBOutlet(并使用IB链接),然后您可以在didSelectRow之外访问它。

@property (nonatomic) IBOutlet UIPickerView *myPickerView;

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

NSString *aCompany = [arrayColour objectAtIndex:[self.myPickerView selectedRowInComponent:0]];