UIActionSheet in a tab view

I was getting problems displaying an action sheet in a view that was contained within a tab control.

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you wish to continue?"
									   delegate:self
									  cancelButtonTitle:@"No"
								   destructiveButtonTitle:@"Yes"
									  otherButtonTitles:nil];
[sheet showInView:self.view];
[sheet release];

The prompt would be displayed but the clicking of the “No” button didn’t always work. The problem is although there is a view that can display the prompt, the correct view to do it is the tab bar, The following code works fine

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you wish to continue?"
									   delegate:self
									  cancelButtonTitle:@"No"
								   destructiveButtonTitle:@"Yes"
									  otherButtonTitles:nil];
[sheet showFromTabBar:self.tabBarController.tabBar];
[sheet release];


3 Responses to “UIActionSheet in a tab view”

  1. [sheet showInView:self.tabBarController.view];

  2. Makzzz, I assume either will work just as well

  3. Thanks very much! works awesome.

Leave a Reply