UIActionSheet
在我的应用程序中,当按下按钮时UIPickerView
,我将在UIToolBar
其中启动。它通过使用以下代码完美地工作。我正在尝试获取选择器值并将该值设置为被调用按钮,但我找不到它的确切解决方案。
- (IBAction)showPicker:(id)sender {
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];//as we want to display a subview we won't be using the default buttons but rather we're need to create a toolbar to display the buttons on
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
//[pickerView release];
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
当按下工具栏中的完成按钮时,它将调用此方法
-(void)doneButtonPressed:(id)sender{
//Do something here here with the value selected using [pickerView date] to get that value
[actionSheet dismissWithClickedButtonIndex:1 animated:YES];
[pickerView release];
[pickerToolbar release];
[actionSheet release];
}
这是我的问题
如何从操作表中获取选择器值?
如何将该值设置为按钮?
谢谢你们的帮助