我正在构建一个 iPad 应用程序,我希望在用户按下按钮(常规按钮,而不是 ToolBarItem)时弹出一个 uipickerview。我意识到通常你会从工具栏上做弹出框类型的东西,但在这种情况下,我需要它发生在标准的按钮点击上。我做了很多搜索,这是我能够想出的代码(这是按钮单击的代码):
- (IBAction)showTagPicker:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select a Category" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect frame = CGRectMake(0, 40, 320, 450);
PCCategory *categories = [[PCCategory alloc] init];
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:frame];
picker.delegate = categories;
picker.dataSource = categories;
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 464)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self
action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(tagSelected)];
[barItems addObject:doneButton];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:picker];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 464)];
}
这似乎确实是在弹出窗口中创建选择器控件,但是该控件非常小(仅显示大约 1 行),并且我显示的工具栏项目都没有呈现。
如何控制大小?我尝试调整正在创建的两个 CGRect 对象的值,但这似乎没有太大区别。