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
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
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?
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.
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;
}
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.