IPad UIActionSheet not showing

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

enter image description here

What is the reason?

My code to display the action sheet

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]; 
+8
iphone cocoa-touch uiactionsheet
source share
2 answers

Replace

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

from

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

or if you want on the iPad Action Sheet, try this custom control https://nodeload.github.com/Arrived/BlockAlertsAnd-ActionSheets/zipball/master

+9
source share

Use the UIActionSheet showFromRect or UIActionSheet showFromBarButtonItem: .

UIActionSheetDelegate -

  - (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 an iPhone app, use the UIActionSheet showInView method -

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

example -

 [actionSheet showInView:self.view.window]; 
0
source share

All Articles