我使用了 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];
最佳答案
替换
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
与
[actionSheet showFromRect:btnShare.frame inView:self.view animated:YES];
或者如果您想要 iPad 中的操作表,请尝试此自定义控件 https://nodeload.github.com/Arrived/BlockAlertsAnd-ActionSheets/zipball/master
关于iphone - iPad UIActionSheet 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9496259/