Ios UIPickerview未出现在正确的位置
很抱歉问这么愚蠢的问题,但我不知道为什么我的UIPickerView with done按钮没有出现在正确的位置。我正在使用以下代码,但我不知道为什么我会遇到这样的问题Ios UIPickerview未出现在正确的位置,ios,objective-c,uipickerview,uiactionsheet,Ios,Objective C,Uipickerview,Uiactionsheet,很抱歉问这么愚蠢的问题,但我不知道为什么我的UIPickerView with done按钮没有出现在正确的位置。我正在使用以下代码,但我不知道为什么我会遇到这样的问题 actionSheet=[[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; UIToolbar *pickerToolba
actionSheet=[[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,320,40)];
[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonTapped:)];
[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(doneButtonTapped:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
//-----------
maritalStatusPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
maritalStatusPickerView.delegate = self;
maritalStatusPickerView.showsSelectionIndicator = YES;
[actionSheet addSubview:maritalStatusPickerView];
[actionSheet showInView:self];
为什么要添加两次maritalStatusPickerView
[self addSubview:maritalStatusPickerView];
[actionSheet addSubview:maritalStatusPickerView];
使用下面的代码
actionSheet=[[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.frame = CGRectMake(0, 234, 320, 256);
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,320,40)];
[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonTapped:)];
[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(doneButtonTapped:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
//-----------
maritalStatusPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
maritalStatusPickerView.delegate = self;
maritalStatusPickerView.showsSelectionIndicator = YES;
// [self addSubview:maritalStatusPickerView];
[actionSheet addSubview:maritalStatusPickerView];
[self.view addSubview:actionSheet];
初始化后,只需将actionsheet的框架包含到代码中即可
actionSheet.frame = CGRectMake(0, 0, 320, 256);
参考此如果要从视图底部打开pickerview,您必须在视图中添加操作表,并更改坐标
[actionSheet addSubview:maritalStatusPickerView];
//Replace this : [actionSheet showInView:self];
[self.view addSubview:actionSheet];
您的图像未正确设置,请张贴错误添加的完整屏幕快照,但即使在删除后,也无法正常工作