Search code examples
iosobjective-cuiactionsheet

Add Actionsheet in UITabbarcontroller in iOS


I created UITabbar in UIViewController. Then i added a UIActionSheet to it but when the actionsheet appeared, when top part of button "Cancel" is clicked, it works, but when I click the bottom part of "Cancel", there's no response. I used this code to add the actionsheet:

actionSheetDelete = [[UIActionSheet alloc] initWithTitle:@"Do you want to continue?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Item(s)" otherButtonTitles:nil];
actionSheetDelete.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheetDelete showInView:self.view];
[actionSheetDelete release];

When i click on action sheet, i always show this alarm in console:

Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].

Do you have any suggestion? Thanks in advance


Solution

  • You could show it in the view of the UITabBarController:

    actionSheetDelete = [[UIActionSheet alloc] initWithTitle:@"Do you want to continue?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Item(s)" otherButtonTitles:nil];
    actionSheetDelete.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    [actionSheetDelete showInView:self.tabBarController.view];
    [actionSheetDelete release];
    

    Alternatively, a slightly more robust version might be:

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