在我的應用中,當按下按鈕時,我將啓動UIActionSheet
,其中UIPickerView
和UIToolBar
位於其中。它的工作完美通過使用下面的代碼。 我想獲取選擇器值並將該值設置爲被調用按鈕,但我找不到確切的解決方案。如何從iOS中的操作表中獲取pickervalue?
- (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];
}
這裏是我的問題
如何從動作片的選擇器值?
如何將該值設置爲按鈕?
感謝您的幫助球員
感謝您的答案..我想在'doneButtonPressed'方法中使用它..以及如何從此phik中獲取選擇器值..謝謝 – GoCrazy 2012-08-01 12:47:19
是的,在doneButtonPressed中做到了這一點。該值在數據源中,所以使用'[self pickerView:pickerView titleForRow:row forComponent:0]'。 – Felix 2012-08-01 12:50:33
感謝您的支持..對不起,接受剛纔的答案有一個更改來測試我的代碼..謝謝+1 – GoCrazy 2012-08-02 10:29:19