iPad UIActionSheet not showing
Asked Answered
P

2

8

I used code from this post to display a action sheet in my application. But it shows like

enter image description here

What will be the reason?

My code to display action sheet is

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                         delegate:nil
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 40, 300, 300);

UIView *pickerView = [[UIView alloc] initWithFrame:pickerFrame];
pickerView.backgroundColor=[UIColor blackColor];

[actionSheet addSubview:pickerView];


UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];


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

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

[self.view addSubview:actionSheet];
Plinth answered 29/2, 2012 at 9:9 Comment(1)
Atleast give some title to buttons. Otherwise it won't show up.Failing
I
9

Replace

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

with

 [actionSheet showFromRect:btnShare.frame inView:self.view animated:YES];

or if you want Action sheet in iPad then try this custom control https://nodeload.github.com/Arrived/BlockAlertsAnd-ActionSheets/zipball/master

Immersed answered 29/2, 2012 at 10:45 Comment(0)
D
0

Use UIActionSheet showFromRect or UIActionSheet showFromBarButtonItem: method.

UIActionSheetDelegate methods are -

 - (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;
 - (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated; 

example:

[actionSheet showFromRect:self.btnShare.frame inView:self.view animated:YES];

If you are using for iPhone app use UIActionSheet showInView method -

- (void)showInView:(UIView *)view;

example -

[actionSheet showInView:self.view.window];
Dorcus answered 8/6, 2015 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.