last Button of actionsheet does not get clicked
Asked Answered
D

3

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

Diction answered 15/12, 2010 at 7:14 Comment(3)
Please post your some code, then easily we can help you to resolve it.Phenology
You just cant use any of the showFromTabBar methods, if you're using some custom tabbars. stackr tell the bets answer!Danu
@WinDMak3r - Yes I know and that is why he got 32 upvotes :)Diction
K
82

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]

Kahn answered 15/12, 2010 at 8:14 Comment(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.Albatross
i was having same problem and after i see @Kahn answer i jumped in joy..thanks a ton man..Cameo
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 TranKahn
B
3

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

Boondoggle answered 15/12, 2010 at 7:24 Comment(5)
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];Diction
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...)Boondoggle
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....Diction
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'Diction
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)Boondoggle
W
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;
}
Whittemore answered 11/1, 2012 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.