4

将 Xcode 6 与 iOS 8 SDK 一起使用,最低支持为 iOS 7。

此代码不适用于 iPhone 5s 8.0、iPhone 6、iPhone 6 Plus,但适用于 iPhone 5 8.0 和 iPhone 4s 8.0。

它有一个文本字段。文本字段有一个 inputView 和 inputAccessoryView 来显示一个日期选择器和带有一个按钮的工具栏。

我只做了足够的事情来证明这个问题。在那些更高的模型模拟器上,只显示工具栏而不显示选择器。

这是模拟器中的错误还是 iOS 8 中仍然有效的更改?

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43, 320, 480)];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    [pickerView setShowsSelectionIndicator:YES];
    pickerView.backgroundColor = [UIColor whiteColor];
    _textField.inputView = pickerView ;
    _textField.delegate = self;

    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
    toolbar.barStyle = UIBarStyleBlackOpaque;
    [toolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];
    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:nil];
    [barItems addObject:doneBtn];
    [toolbar setItems:barItems animated:YES];

    _textField.inputAccessoryView = toolbar;


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return 3;
}

@end
4

3 回答 3

4

检查您的 iOS 模拟器的硬件键盘状态。在 iOS 模拟器菜单栏中,转到硬件 > 键盘并取消选择连接硬件键盘选项。

于 2014-10-13T23:03:24.397 回答
0

您可以将工具栏样式更改为默认值并检查。这个对我有用。

于 2014-11-14T14:02:11.077 回答
0

每当您有一个文本字段处于焦点并且键盘没有出现时,当模拟器是焦点窗口时,请尝试使用您的物理键盘 command+k 或硬件 > 键盘 > 从 Mac 的顶部栏中切换软件键盘。

于 2014-10-13T23:17:00.133 回答