John Doh
John Doh

Reputation: 249

Why is my UIActionSheet hidden by my TabBarController?

I am having a problem correctly implementing a UIActionSheet in an iPad 5.1 (XCode 4.3) project. I can populate it correctly with all the items I need. The list is longer than the window, but the scrollbars automatically come up, etc. However, the cancel button (which I presume is supposed to be at the end) is coming up half hidden behind my tab bar. Shown below:

(sorry, SO won't let me post images yet)

Here is my storyboard setup: The entry point is that Tab Bar Controller on the left, which goes to another Navigation Controller (center), which has the View Controller on the right as the root view. http://i854.photobucket.com/albums/ab103/srVincentVega/ScreenShot2012-06-28at52713PM.png

I have tried presenting the UIActionSheet in all sorts of ways, but this odd behavior persists, and I can't figure out how to address it

- (IBAction)cmdReason:(id)sender
{
    NSArray *reasons = [AppState getInspReasons];

    UIActionSheet *action = [[UIActionSheet alloc]
                             initWithTitle:@"Reason for Inspection"
                             delegate:self
                             cancelButtonTitle:@"Cancel"
                             destructiveButtonTitle:nil
                             otherButtonTitles:nil];

    for (NSString *rsn in reasons)
    {
        [action addButtonWithTitle:rsn];
    }

    [action showInView:self.view];
}

I have tried the various methods to show "action" - showFromTabBar, showFromToolbar, etc - I am VERY new to this development environment, so I am not up to speed yet on how these items interact at this level. Does anyone have a suggestion for how I can present this correctly?

I am sorry if this has already been asked elsewhere. I have spent all day trying bits of code from all over the web, including SO. I don't know if it's something to do with my storyboard layout, or what.

One further thing - when I rotate the emulator, the action sheet does redraw, but the bit at the end there gets wonky looking, like it can no longer figure out how to draw it.

Many thanks!

EDIT: I have put together a very small project that demonstrates this exact behavior. I don't have a good way to host the zip file, so I put on google docs and shared it. The link is below. If you click on that, there should be a download option under file that will give you the original zip file.

https://docs.google.com/open?id=0B7IYvy9_c_NLaEFneGc5bzc2S2c

Upvotes: 1

Views: 1066

Answers (3)

0x8b4df00d
0x8b4df00d

Reputation: 53

Seems like there is not a real solution for this. It looks like it's a limitation with UIActionSheet if you add that amount of button titles and present that from a tab bar.

Beside that, the proper way to display an UIActionSheet from a tab bar is to use

[action showFromTabBar:self.tabBarController.tabBar];

instead of

// Taken from your example project
AppDelegate *d = [[UIApplication sharedApplication] delegate];
UIWindow *w = d.window;
UIViewController *vc = w.rootViewController;
UITabBarController *c = (UITabBarController *)vc;
UITabBar *t = c.tabBar;
[action showFromTabBar:t];

Upvotes: 1

Rich Tolley
Rich Tolley

Reputation: 3842

Try this:

CGRect r = CGRectMake(x, y, w, h); //change values to fit location of button
[actionSheet showFromRect:r inView:self.view animated:YES];

I used it on one of my apps with the same problem and the dismiss button showed up ok.

Upvotes: 0

rooster117
rooster117

Reputation: 5552

I would think if you got a reference to the tab bar controller then you should be able to present it from that. You can try showing it from the main window but I would think you shouldn't rely on that.

[action showInView:[[UIApplication sharedApplication] keyWindow]];

Upvotes: 0

Related Questions