karse23
karse23

Reputation: 4115

Problems with UIActionSheet on iPad

I'm making an application compatible for iPhone and iPad and I'm showing a picker in a actionsheet as follows:

actionSheet = [[UIActionSheet alloc] initWithTitle:@"Day / Month"
                                          delegate:self
                                 cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                                 otherButtonTitles:nil];

picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,40,0,0)];
picker.delegate = self;
picker.showsSelectionIndicator = YES;
[actionSheet addSubview:picker];

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet setBounds:CGRectMake(0,0,320,469)];

This works well for iPhone, but for the iPad version with the same code and leaving aside those who are different dimensions gives me the following error:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil'

At this line:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

I've tried with showInView:self.view , self.Window, self.view.superview but nothing...

I want to know what gives that error and will not let me do it the same way... thanks in advance!

Upvotes: 2

Views: 3852

Answers (1)

Akshay
Akshay

Reputation: 5765

An action sheet is transformed to a pop-over on the iPad. There are two methods to display a pop-over-

 - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view
 permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
 animated:(BOOL)animated;

 - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
 permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
 animated:(BOOL)animated;

Guessing from this, I think you can try using one of the following methods for presenting the action sheet-

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated 
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated

instead of using showInView:.

Upvotes: 6

Related Questions