1

Sams **Teach Yourself iPad Application development in 24 hour's says I can "display an action sheet in a "nonanimated" fashion, filling a full popover view when it first appears...To do this, you need to show the action sheet with the method

showFromRect:inView:animated

with the "rect" set to the dimensions of the popover, the view set to the popover view controller's view, and "animated" set to false. The display of the action sheet would need to take place when the popover view is first loaded such as in the viewDidLoad method of the popover view controller.

OK, easy.. here's my code in my popover's viewDidLoad method:

- (void)viewDidLoad {

self.contentSizeForViewInPopover=CGSizeMake(400.0,400.0);


    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Available Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"Negotiate", @"Compromise", nil];

    [actionSheet showFromRect:[self.view bounds] inView:self.view  animated:NO];

    [actionSheet release];

    [super viewDidLoad];
}

But this fails every time at the inView:self.view parameter with the exception:

Invalid parameter not satisfying view != nil

Any ideas?

Note, if I put this exact same code in an IBAction method and trigger it from a button in the popover, it works without a hitch!

PengOne
  • 48,188
  • 17
  • 130
  • 149
PapillonUK
  • 642
  • 8
  • 20

2 Answers2

2

One solution is to call the UIActionSheet in viewWillAppear or viewDidAppear: For example:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self showActionSheet];
}

- (void)showActionSheet {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Available Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"Negotiate", @"Compromise", nil];

    [actionSheet showFromRect:[self.view bounds] inView:self.view  animated:NO];

    [actionSheet release];
}
PengOne
  • 48,188
  • 17
  • 130
  • 149
  • To test this theory I tried adding a UILabel using [self.view addSubview] and that works fine! – PapillonUK Jul 06 '11 at 21:01
  • @PapillonUK: Have you tried calling the actionSheet in `viewWillAppear` instead? – PengOne Jul 06 '11 at 21:03
  • PengOne - that works! I've never used viewWillAppear before - can you explain why that would work? – PapillonUK Jul 06 '11 at 21:08
  • Well, I believe the actionSheet can't be deployed onto a view that isn't currently visible, because the actionSheet needs to block all things behind it. This is a theory. I'll look into it a bit and update my answer. – PengOne Jul 06 '11 at 21:10
  • OK PengOne - i'll mark that as the answer. Perhaps the Sam's book is incorrect. I also notice that the action sheet still scrolls up in an animated fashion even though I set animated:NO. I think i'm in uncharted territory here - can't seem to find much on this method by Googling either! Thanks for your help! – PapillonUK Jul 06 '11 at 21:21
  • @PapillonUK: Books are sometimes fallible. By googling, I found two other posts on other forums with similar issues (never resolved). I think it must be a quirk of UIActionSheet, but I cannot find documentation on it. – PengOne Jul 06 '11 at 21:25
0

self.view hasn't been instantiated completely yet when this code is called.

I would suggest, as a hacky alternative, to put in a short (.1 seconds or something) NSTimer with your IBAction method as the callback.

Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56