gpt4 book ai didi

iphone - UIPickerView 选择和隐藏

转载 作者:可可西里 更新时间:2023-11-01 03:01:31 26 4
gpt4 key购买 nike

如何使 UIPickerView 像带有下拉选择框的 webview 一样工作,而不是像通常的网站那样下拉,iphone使其成为包含所有选择的 UIPickerView。当您选择一个时,您的选择旁边会显示一个复选标记并更改下拉框的值。以及如何将“完成”按钮放在 UIPickerView 顶部以关闭 UIPickerView

我已经知道 [pickerview setHidden:YES] 是用来隐藏 pickerview 的方法。我只是不知道如何在 UIPickerView 中包含“完成”按钮。

问候,克里斯

最佳答案

这段代码将作为键盘滑出一个选择器 View ,并在其顶部附加一个完成按钮。基本上,您想使用输入字段设置一个 inputAccessoryView。您应该在输入字段的触及事件上调用此方法。

- (IBAction)showYourPicker:(id)sender {

// create a UIPicker view as a custom keyboard view
UIPickerView* pickerView = [[UIPickerView alloc] init];
[pickerView sizeToFit];
pickerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
self.yourPickerView = pickerView; //UIPickerView

yourTextField.inputView = pickerView;

// create a done view + done button, attach to it a doneClicked action, and place it in a toolbar as an accessory input view...
// Prepare done button
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
keyboardDoneButtonView.barStyle = UIBarStyleBlack;
keyboardDoneButtonView.translucent = YES;
keyboardDoneButtonView.tintColor = nil;
[keyboardDoneButtonView sizeToFit];

UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered target:self
action:@selector(pickerDoneClicked:)] autorelease];

[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]];

// Plug the keyboardDoneButtonView into the text field...
yourTextField.inputAccessoryView = keyboardDoneButtonView;

[pickerView release];
[keyboardDoneButtonView release];
}

最后,您的完成按钮调用“pickerDoneClicked”方法,您应该在其中添加[yourTextField resignFirstResponder]; 这将隐藏选择器 View 。

关于iphone - UIPickerView 选择和隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5347537/

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