0

Hi My UI Picker no longer works on iOS7, it pops up but it is blank. Only happened on iOS7.

//picker
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
animationsLabel.text = [optionsArray objectAtIndex:[picker selectedRowInComponent:0]];

if (pickerView==animationsPicker) {
    animationsLabel.text = [optionsArray objectAtIndex:[animationsPicker selectedRowInComponent:0]];
}

}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [optionsArray count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
   return [optionsArray objectAtIndex:row];
   NSLog(@"title options array %lu",(unsigned long)optionsArray.count);
}

And the action:

-(IBAction)animationActionSheet:(id)sender {

UIActionSheet *selectPopup = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n"
                                                        delegate:nil
                                               cancelButtonTitle:nil
                                          destructiveButtonTitle:nil
                                               otherButtonTitles:nil];

[selectPopup showInView:self.view];

optionsArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"6",@"5",@"7",@"8",@"9", nil];

// Create picker
animationsPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 160, 320, 100)];
animationsPicker.showsSelectionIndicator = YES;
[self.view addSubview:animationsPicker];
animationsPicker.delegate = self;
animationsPicker.dataSource = self;
[selectPopup addSubview:animationsPicker];

// Animate picker opening
[UIView beginAnimations:nil context:nil];
[selectPopup setBounds:CGRectMake(0, 0, 320, 485)];
[UIView commitAnimations];
}

This is what I have tried so far. There was never a problem displaying the picker in the an Action sheet before, but now it is blank. Im wondering did anyone else come across this problem, or can you see any errors? I printed everything to do with the picker.

3 Answers 3

5

I was told that putting pickers in Action Sheets was non-standard. I never had any problems doing this in iOS 6, but in iOS 7, I got errors. I switched to UIView instead of action sheets for my pickers and it works fine. I hope this helps.

2
  • Thanks very much. I was hoping that wouldnt be the case, but it should be simples to fix. I was hoping to keep it the same. Thanks again.
    – DevC
    Oct 1, 2013 at 21:26
  • I was hoping that too, but it's not bad to put them in UIViews instead of ActionSheets. Good luck!
    – Barb
    Oct 1, 2013 at 21:29
2

Adding subviews is not recommended for the action sheet, per documentation.

"Subclassing Notes UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:."

Apple is reinforcing their usage for Action Sheets....and they upped the ante for this to work in iOS 7, which means you have to code around it.

0

Check out this project I made. It's practically the same thing as having a picker inside an action sheet https://github.com/DiscoverPioneer/PickerSlider

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.