4

iOS 8 SDK で Xcode 6 を使用し、iOS 7 としてサポートされている最小値。

このコードは、iPhone 5s 8.0、iPhone 6、iPhone 6 Plus では機能しませんが、iPhone 5 8.0 および iPhone 4s 8.0 では機能します。

1 つのテキスト フィールドがあります。テキスト フィールドには、日付ピッカーとツールバーを 1 つのボタンで表示するための 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

0

ツールバーのスタイルをデフォルトに変更して確認できます。わたしにはできる。

于 2014-11-14T14:02:11.077 に答える