- (void) actionsheetstart
{
actionSheet=[[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet showInView:self.view];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 480, 32)];
[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancel_clicked:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done_clicked:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
UIPickerView *picker = [[UIPickerView alloc] init];
picker.frame = CGRectMake(0, 44, 320, 216);
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
[actionSheet addSubview:picker];
}
-(void)done_clicked:(id)sender
{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
-(void)cancel_clicked:(id)sender
{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
由于某种原因,动作表很好,但UIPickerView和UIToolBar疯了。 我尝试将帧设置为-px但没有任何成功。什么似乎是问题?
非常感谢。
答案 0 :(得分:3)
请勿在{{1}}内插入UIPickerView
,否则您将无法以这种方式获得正确的行为。我的解决方案:
UIActionSheet
,实施方法UIButton
,返回canBecomeFirstResponder:
。YES
中实施inputView
方法,返回UIButton
。UIPickerView
方法,以返回选择器上方的工具栏。inputAccessoryView
按钮。Voila,当你按下按钮时,你的选择器会像键盘一样显示模式。
修改强>
MyButton.h
becomeFirstResponder:
MyButton.m
#import <UIKit/UIKit.h>
@interface MyButton : UIButton
@end