我想在选择器 View 上方显示一个选择器 View 和一个完成按钮。
我有一个自定义标签,它将成为第一响应者。因此,当它成为第一响应者时,我将显示一个选择器 View 作为我的标签的输入 View 。
现在我想在选择器上有一个完成按钮来关闭选择器 View 。我玩过 UIPickerView 的 inputAccessoryView 属性,但没有成功。 inputAccessoryView 可以用 UITextView ,不确定 UIPickerView 。这是如何使用 UITextView
UITextView with “Done” button and “Return” key?
有没有人试过这个,如果有人知道如何为选择器做这个,请回答。
提前谢谢大家!!
最佳答案
将您的选择器 View 添加到操作表。首先确保您的 View Controller 实现了 UIPickerViewDelegate 和 UIActionSheetDelegate。
然后添加这个方法,当你想显示你的选择器时调用它。
- (void)showPicker {
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Pick Value"
delegate:self
cancelButtonTitle:@"Done"
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,180,0,0)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[menu addSubview:pickerView];
[menu showInView:self.view.superview];
//Change the height value in your CGRect to change the size of the actinsheet
[menu setBounds:CGRectMake(0,0,320, 615)];
[pickerView release];
[menu release];
}
关于iphone - 如何在 pickerview 上添加完成按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5591815/