Let’s say you want to use UIActionSheet to show three buttons to the user with a cancel buttons in a UIView, which itself is managed by a UITabBarController:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@”Action Title” delegate:self cancelButtonTitle:@”Cancel” destructiveButtonTitle:nil otherButtonTitles:@”Option 1″, @”Option 2″, @”Option 3″, nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
[actionSheet release];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@”Action Title” delegate:self cancelButtonTitle:@”Cancel” destructiveButtonTitle:nil otherButtonTitles:@”Option 1″, @”Option 2″, @”Option 3″, nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
UIApplicationDelegate *appDelegate = (UIApplicationDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabBarController = appDelegate.tabBarController;
[actionSheet showInView:tabBarController.view];
[actionSheet release];
Thanx a lot, was the exact issue I had…
Two small errors in your code : ApplicationDelegate doesn’t exist, it’s UIApplicationDelegate.
Second : for a reason I can’t explain, never managed to get the correct includes so that UIApplicationDelegate is recognized (though I had included the UIKit framework and had this line on top : #include … Well had a workeround like this :
[actionSheet showInView:self.tabBarController.view];
My view hierarchy is window > UITabBarViewControler > UINavigationControler > UIViewControler which pushed the UIViewControler in which I had the problem.
So don’t ask me how it could find the reference to the root tabBarControler.view just with “self.tabBarControler.view” but all I know is that it works !
By the way, happy to know I’m not the only developer working on both .Net projects and iPhone apps !
LikeLike
To use UIApplicationDelegate, you’ll have to import ApplicationDelegate.h like:
#import “ApplicationDelegate.h”
LikeLike