gpt4 book ai didi

iphone - 显示 pickerview 和操作表

转载 作者:行者123 更新时间:2023-11-29 11:00:01 24 4
gpt4 key购买 nike

我有一个文本框。一旦我点击它,我想要一个 UIPickerView 弹出并从 UIPickerView 中选择一个项目,一旦我完成了选择,我想通过点击确认选择在上面有确认按钮的 UIActionSheet 上。所以我的要求是有一个 UIActionSheet 并在其下方有一个选择器 View 。我只是 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;

最佳答案

这样试试,

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 {
}

它会像,

enter image description here

关于iphone - 显示 pickerview 和操作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16373796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com