24

I have used an actionsheet in my project and when it appears it show all buttons but last (4th) button does not responds to my click(only it's half part responds)..

I know the reason it is because i have used a TabBarController and the present class is inside that tabbar controller.... only that part of the actionsheet is responding which is above the tabs....and my last button is half above and half is on top of tabbar

please help

stackr
  • 2,714
  • 24
  • 44
Ranjeet Sajwan
  • 1,888
  • 2
  • 28
  • 60

3 Answers3

83

i suggest using this:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

I had the same problem that you have and using this method to show it worked for me. The TabBar wants to stay key Window what makes your bottom button appear above, but is actually under the tabbar.

Hope this does the trick for you..

Edit

If you use landscape mode and the method above doesn't work. You can use the following fix:

@Vinh Tran: [sheet showFromTabBar:self.parentViewController.tabBarController.tabBar]

Community
  • 1
  • 1
stackr
  • 2,714
  • 24
  • 44
  • 3
    This idea only works, if the view doesnt use the landscape mode. in landscape mode I get the actionsheet presented from portrait mode. So for landscape I used the [sheet showFromTabBar:self.parentViewController.tabBarController.tabBar] instead. – Vinh Jun 01 '12 at 19:48
  • i was having same problem and after i see @stackr answer i jumped in joy..thanks a ton man.. – Pranjal Bikash Das Sep 12 '12 at 06:46
  • Updated and should be correct again now. :) @newenglander... Downvoting for an answer that is almost 3 years old is a bit much don't you agree? The answer is correct, and the owner was satisfied. But to make the other people happy i also added the answer from Vinh Tran – stackr Jul 03 '13 at 14:27
3

What method do you use to show your actionsheet. Try showFromTabBar: method

Vladimir
  • 167,138
  • 35
  • 380
  • 310
  • I have use-------- UIActionSheet *actionsheet=[[UIActionSheet alloc]initWithTitle:@"Select feed type" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"first",@"2nd",@"3rd",@"4th",nil]; [actionsheet showInView:self.view]; [actionsheet release]; – Ranjeet Sajwan Dec 15 '10 at 07:41
  • try using method I suggested instead of showInView:. as I understand it is designed to handle exactly your case (have not used it myself though...) – Vladimir Dec 15 '10 at 07:47
  • according to your suggestion i used following method......[actionsheet showFromTabBar:delegate.tabC.tabBar]; ...where delegate is object of my delegate class where is tabbarController tabC...............But my program CRASHED.... – Ranjeet Sajwan Dec 15 '10 at 07:51
  • following is the error..........2010-12-15 13:18:39.876 BabyCare[6338:207] *** Assertion failure in -[UIActionSheet _presentSheetFromView:above:], /SourceCache/UIKit_Sim/UIKit-1261.5/UIActionSheet.m:1715 2010-12-15 13:18:39.878 BabyCare[6338:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil' – Ranjeet Sajwan Dec 15 '10 at 07:52
  • Check if delegate.tabC.tabBar is not nil may be? I created sample project and that method works fine there ( I used self.tabBarController.tabBar in current view controller to get tabBar) – Vladimir Dec 15 '10 at 08:25
0

The real problem comes in, when your interface is rotated to landscape and the parent view controller has a transformation on it. Believe me, that's a realistic scenario, doh. Then the action sheet is clipped and you can't use the parentViewController because it is transformed. The solution to avoid all these issues is to create a new window, add a rotatable view controller as rootViewController and use its view to display the sheet.

CGRect applicationRect = [[UIScreen mainScreen] bounds];
UIWindow* actionSheetWindow = [[UIWindow alloc] initWithFrame:applicationRect];
RotationViewController* rootViewController = [[RotationViewController alloc] initWithNibName:nil bundle:nil];
actionSheetWindow.rootViewController = rootViewController;
[rootViewController release];
actionSheetWindow.hidden = NO;

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil];
[actionSheet setCancelButtonWithTitle:@"Cancel" handler:^{
    actionSheetWindow.hidden = YES;
    [actionSheetWindow release];
}];

[actionSheet showInView:rootViewController.view];

The code above uses BlocksKit, but you can do it also by using the actionSheet delegate and instance properties.

RotationViewController is just a UIViewController subclass that implements

- (void) viewDidLoad {
   [super viewDidLoad];
   self.view.backgroundColor = [UIColor clearColor];
   self.view.opaque = NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return YES;
}
Martin Hering
  • 419
  • 3
  • 11