views:

834

answers:

4

Is there a way to call an ActionSheet directly from a tabbar. I'm working on a program where the user wants a contact button on the tab bar that displays an actionsheet with the appropriate buttons.

Thanks in advance

+1  A: 

Couldn't you just have a view controller associated with one of the tabs, and then leave its view plain, and in viewDidLoad make the actionSheet?

Mk12
It screws up the view under it.
Steve Gibson
Oh you mean you want clicking the tab bar to open up an actionsheet on top of the current view?.. Maybe you could do what I said but then load the previous view as a subview into the new one.. or something.. Why not have an entire new view to write the message or whatever?
Mk12
That's exactly what I wan to do. The user(s) don't want a new view they are insisting on a actionsheet (they like the size and transparency). Just trying to figure out a way to do it. You original way wipes out part of the tableview and the actionsheet never is displayed.
Steve Gibson
A: 

An example would be the mail app were your viewing an email and you hit curved arrow button to bring up the "forward - reply" action sheet.

Steve Gibson
No, mail uses a UIToolbar, not a UITabBar like you want.. You shouldn't do what you're trying to do anyway, UITabBars are for naviagting between sections of the app, not to perform an action (like contacting you).
Mk12
A: 

I agree with all the people above saying that this isn't a good idea (and that this should be done using a toolbar), but it's definitely doable.

The code below implements one of the UITabBarControllerDelegate methods, and avoids the selection of the tab bar item, and instead creates and displays a UIActionSheet:

-   (BOOL)tabBarController:(UITabBarController *)tabBarController 
shouldSelectViewController:(UIViewController *)viewController
{
    NSInteger choice = 0; // --> index of the view controller that should "act as button"
    if (viewController == [tabBarController.viewControllers objectAtIndex:choice])
    {
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                           delegate:nil 
                                                  cancelButtonTitle:@"Cancel" 
                                             destructiveButtonTitle:@"Delete" 
                                                  otherButtonTitles:@"Send e-mail", @"Whatever", nil];
        [sheet showInView:window];
        [sheet release];
    }
    return NO;
}
Adrian Kosmaczewski
A: 

I think I can understand what Steve's after. I have a main activity reached via the 1st element in the TabBarController. I'd like the 2nd tab-bar element to selectively add either a modalview email, an access to facebook, or an access to twitter. It would be nice if that choice is offered via an actionsheet so as to not lose sight of what's "behind" from that first view controller (from the first tab-bar choice) and THEN the new view controller handling the choice shows up. This seems to be what "AP mobile" does when you want to 'share' a news article, for example.

@Adrian : I couldn't get your solution to work out-of-the-box.. but then found out why (read on...)

It doesn't help (obviously) to specifically drag from the Outlet:delegate to file-owner You'll get: * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'

My delegate method was being ignored until I added the UITabBarControllerDelegate to the interface definition (UIApplicationDelegate was already present and I didn't read further)... AND In applicationDidFinishLaunching I added

[rootController setDelegate:self];

Cheers.

Shawn -DrKdev