iPad的UIActionSheet未显示

8

我使用了这篇文章中的代码在我的应用程序中显示操作表。但是它显示如下:

enter image description here

这是什么原因呢?

我用来显示操作表的代码是:

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];

至少为按钮命名一个标题。否则它将不会显示。 - Parth Bhatt
2个回答

9

0
使用UIActionSheet showFromRectUIActionSheet showFromBarButtonItem:方法。 UIActionSheetDelegate方法包括 -
 - (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;
 - (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated; 

例子:

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

如果您正在使用iPhone应用程序,请使用UIActionSheet showInView方法 -
- (void)showInView:(UIView *)view;

例子 -

[actionSheet showInView:self.view.window];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接