iphone - 如何在 pickerview 上添加完成按钮?

标签 iphone objective-c uiview uitextview uipickerview

我想在选择器 View 上方显示一个选择器 View 和一个完成按钮

我有一个自定义标签,它将成为第一响应者。因此,当它成为第一响应者时,我将显示一个选择器 View 作为我的标签的输入 View 。 现在我想在选择器上有一个完成按钮来关闭选择器 View 。我玩过 UIPickerViewinputAccessoryView 属性,但没有成功。 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/

相关文章:

iphone - 将 NSData 转换为 int

objective-c - 防止其他窗口在 Cocoa 中获得焦点

iphone - UIView animateWithDuration :delay: working weird

ios - 为什么 UIViewController 的 'view' 属性在 Swift 中不是可选的?

iphone - 由于内存问题/MBProgressHUD 指示器导致应用程序崩溃

iphone - 为什么AVAudioPlayer没有响应?

ios - 以编程方式添加的 ViewController 看起来已移动/转换(iOS、swift、 Storyboard)

iphone - 核心数据获取不一致

objective-c - 可以使用 Class 对象来转换 Objective-C 对象吗?

ios - TableView 设计问题