0

このようなばかげた質問をして申し訳ありませんが、完了ボタン付きのUIPickerViewが正しい場所に表示されない理由がわかりません。次のコードを使用していますが、なぜこのような問題が発生するのかわかりません。

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];

ここに画像の説明を入力してください

4

4 に答える 4

1

以下のコードを使用してください

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];
于 2013-03-13T12:11:13.973 に答える
0

maritalStatusPickerViewを2回追加する理由

[self addSubview:maritalStatusPickerView];

[actionSheet addSubview:maritalStatusPickerView];
于 2013-03-13T11:58:37.273 に答える
0

初期化後にアクションシートのフレームをコードに含めるだけです

actionSheet.frame = CGRectMake(0, 0, 320, 256);

この質問を参照してください

于 2013-03-13T12:16:02.770 に答える
0

ビューの下部からピッカービューを開きたい場合は、ビューにアクションシートを追加し、座標を変更する必要があります。

[actionSheet addSubview:maritalStatusPickerView];

//Replace this :  [actionSheet showInView:self];

[self.view addSubview:actionSheet];
于 2013-03-13T12:18:20.587 に答える