我有一个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];
}
答案 0 :(得分:2)
将pickerView
设置为IBOutlet
(并使用IB链接),然后您可以在didSelectRow
之外访问它。
@property (nonatomic) IBOutlet UIPickerView *myPickerView;
然后您可以在DoneButton
中使用以下行:
NSString *aCompany = [arrayColour objectAtIndex:[self.myPickerView selectedRowInComponent:0]];