Search code examples
iphoneuiactionsheetiphone-sdk-3.0

UIActionSheet does not show -- the screen just gets darker


I have an iPhone application which is based on the "Window based application" template and which uses a main view with some embedded subviews.

For some action I need a confirmation by the user. Therefore, I create an UIActionSheet and ask the user for feedback.

The problem is, that the action sheet does not show at all. Instead, the screen gets darker. The sheet and the requested buttons do not show. After that, the application hangs. The darkening of the screen is a normal behavior as part of the animation which normally shows the action sheet.

Curiously, the same code works fine, if invoked in the viewDidLoad method. It does not work if invoked in the buttonPressed method which starts the action requiring the confirmation.

- (void) trashButtonPressed {
   // This method is called in the button handler and (for testing
   // purposes) in the viewDidLoad method.
   NSLog( @"trashButtonPressed" );

   UIActionSheet* actionSheet =
        [[UIActionSheet alloc] initWithTitle: @"Test" 
                                    delegate: self 
                           cancelButtonTitle: @"Cancel"
                      destructiveButtonTitle: @"Delete Sheet"
                           otherButtonTitles: nil];

   [actionSheet showInView: self.view];
   [actionSheet release];
}

- (void)       willPresentActionSheet:(UIActionSheet *)  actionSheet {
   NSLog( @"willPresentActionSheet" );
}

- (void)       didPresentActionSheet:(UIActionSheet *)   actionSheet {
   NSLog( @"didPresentActionSheet" );
}

- (void)        actionSheet:(UIActionSheet *)actionSheet
  didDismissWithButtonIndex:(NSInteger)buttonIndex {
   NSLog( @"actionSheet:didDismissWithButtonIndex" );
}

As you can see, I have added some logging messages to the protocol handlers of the UIActionSheetDelegateProtocol. The "will present" and "did present" methods get called as expected, but the sheet does not show.

Does anybody know, what's wrong here?


Solution

  • I wonder if [actionSheet showInView: self.view]; is enough to have the actionSheet have itself retained by self.view. (edit: retain count jumps from 1 to 4 so not a problem here)

    Have you checked the dimensions of your view? The sheet is positioned within the view, but if self.view would refer to a big scrollview, you might just have a sheet below the surface. In short, are you sure that self.view.frame and self.view.bounds have the same values in the two situations you are referring to? Is it the same view (when just NSLog(@"%x",self.view)-ing it's address)?

    edit to clarify: do

    NSLog(@"%f %f %f %f",
            self.view.frame.origin.x,self.view.frame.origin.y,
            self.view.frame.size.width,self.view.frame.size.height);
    

    and please tell what you see on the console. I get your "screen just gets darker" if I set either a 0,0,0,0 frame or a 0,0,320,800 frame, so this might be it...