我使用this帖子中的代码在我的应用程序中显示操作表。但它显示像
原因是什么?
显示操作表的代码是
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];
答案 0 :(得分:9)
替换
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
与
[actionSheet showFromRect:btnShare.frame inView:self.view animated:YES];
或者如果您想在iPad中使用操作表,请尝试使用此自定义控件 https://nodeload.github.com/Arrived/BlockAlertsAnd-ActionSheets/zipball/master
答案 1 :(得分:0)
使用UIActionSheet showFromRect
或UIActionSheet 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];