You can't call the ActionSheet in the -viewDidLoad method since the view has not yet been assigned to a window.
Try this short experiment. Add the following to
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"in application did finish launching");
// Override point for customization after app launch.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
NSLog(@"in application did finish launching");
return YES;
}
Code:
- (void)viewDidLoad {
NSLog(@"in view did load");
[super viewDidLoad];
}
and note the flow.
Since viewController has not yet been assigned to a window you can't tell the action sheet to display itself. There is no window yet, for it to do so. You can either create an action method in your viewController activated by a button in the interface for example, or do the following:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"in application did finish launching");
// Override point for customization after app launch.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
NSLog(@"in application did finish launching");
UIActionSheet *action = [[UIActionSheet alloc]
initWithTitle:@"Title of ActionSheet"
delegate:viewController
cancelButtonTitle:@"OK"
destructiveButtonTitle:@"Delete Message"
otherButtonTitles:@"Option 1", @"Option 2",nil];
[action showInView:viewController.view];
[action release];
return YES;
}
To test out the code snippet.
Also make sure that the viewController conforms to the <UIActionSheetDelegate>
If you include this in your header the initWithTitle⦠method should autocomplete
Bob