1

テキストフィールドがあります。をタップすると、UIPickerViewポップアウトしてからアイテムを選択し、選択が完了したら、確認ボタンが付いているをUIPickerViewタップして選択を確認したいのでUIActionSheet、私の要件はUIActionSheetその下にはピッカー ビューがあります。私は iOS 開発の初心者であり、技術用語にまだ慣れていません。ですから、私の非公式な質問方法にはご容赦ください。

これが私のコードブロックです:

UIPickerView と UIActionSheet の作成

UIActionSheet *confirmRoomSelectionAS =[[UIActionSheet alloc]initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Done",nil];

UIPickerView *roomTypePicker=[[UIPickerView alloc]init];

[confirmRoomSelectionAS addSubview:roomTypePicker];
[confirmRoomSelectionAS showInView:self.view];
[confirmRoomSelectionAS setBounds:CGRectMake(0, 0, 320, 600)];

[roomTypePicker setFrame:CGRectMake(0, 170, 320, 216)];
[roomTypePicker setDataSource:self];
[roomTypePicker setDelegate: self];
roomTypePicker.showsSelectionIndicator = YES;
4

2 に答える 2

2

このようにしてみて、

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet showInView:[self.view window]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 390)];
[actionSheet addSubview:[self createToolbar:@"Test"]];

UIPickerView *picker = [[UIPickerView alloc] init];
picker.frame = CGRectMake(0, 44, 320, 162);
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
[actionSheet addSubview:picker];

- (UIView *)createToolbar:(NSString *)titleString {

    UIToolbar *inputAccessoryView = [[UIToolbar alloc] init];
    inputAccessoryView.barStyle = UIBarStyleBlackOpaque;
    inputAccessoryView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [inputAccessoryView sizeToFit];
    CGRect frame = inputAccessoryView.frame;
    frame.size.height = 44.0f;
    inputAccessoryView.frame = frame;

    UIBarButtonItem *doneBtn =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
    UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *cancelBtn =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0 , 11.0f, 100, 21.0f)];
    [titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:14]];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setText:titleString];
    [titleLabel setTextAlignment:UITextAlignmentCenter];

    UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithCustomView:titleLabel];


    NSMutableArray *array = [NSMutableArray arrayWithObjects:cancelBtn,flexibleSpaceLeft,title,flexibleSpaceLeft, doneBtn, nil];
    [inputAccessoryView setItems:array];

    [doneBtn release];
    [title release];
    [titleLabel release];
    [flexibleSpaceLeft release];
    [cancelBtn release];

    return [inputAccessoryView autorelease];
}

- (void)done:(id)sender {
}

- (void)cancel:(id)sender {
}

それは次のようになります。

ここに画像の説明を入力

于 2013-05-04T12:43:48.697 に答える