0

I've added an UIPickerView into a UIActionSheet. Everything ok, but my picker can't be scrolled to choose a value. Any suggestions?

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
UIPickerView * picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 270)]; 
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
[actionSheet addSubview:picker];
[picker release];

[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 500)];
[actionSheet release];

Best regards, Dorin

  • Tested this code. It has no issues. What are the `delegate` and `dataSource` methods that you have implemented? – Deepak Danduprolu May 23 '11 at 14:32
  • - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; { return 1; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component; { return [array count]; } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; { return [array objectAtIndex:row]; } – Simina Dorin May 23 '11 at 14:40
  • I was putting this code into the method textFieldShouldBeginEditing. I want to enable value selection for a textField when entering in edit mode. In this case my picker seems to be somehow disabled. When I paste the code in didLoad method everything ok. – Simina Dorin May 23 '11 at 14:48
  • so you're trying to associate this to a text field right? can you paste the entire `textFieldShouldBeginEditing:` method? – Deepak Danduprolu May 23 '11 at 14:55
  • In the textFieldShouldBeginEditing: method I place the code presented in the topic of my question and I return NO. I placed the same code as action for a button and the picker can be scrolled. – Simina Dorin May 23 '11 at 14:58
  • I am unable to recreate your problem. Code out of `textFieldShouldBeginEditing:` is working for me. – Deepak Danduprolu May 23 '11 at 18:20

1 Answers1

0

An alternative solution to what you're trying to achieve is to set text field's inputView and inputAccessoryView. Setting these will replace the standard keyboard and bring in custom views. This includes the picker view. I happened to write a short example in this question here. Take a look and see if it helps.

Community
  • 1
  • 1
Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105