3

今日、 Revealに取り組んでいるときに、iOS 7 のUITextViewのUITextInputTraitsプロトコルの処理にバグがあることに気付きました。

このUITextInputTraitsプロトコルには、ユーザーが をタップしたときにどのような種類のキーボードを表示するかを設定するメソッドがありますUITextView

iOS 7 では、テキスト選択を有効にするかどうかを制御するための新しいselectableプロパティ onも導入されました。これは、UITextView をサブクラス化して no を返すか、代わりに を設定して適切なデリゲート コールバックを処理し、発生する選択を停止するUITextView必要があった iOS の以前のリリースで必要なメソッドよりもはるかに優れています 。canBecomeFirstResponderinputDelegate

残念ながら、iOS 7 で と の両方を NO に設定すると、すべての editableメソッドが機能しなくなります。それらのいずれかを呼び出そうとすると、アプリは例外でクラッシュします。プロトコルで宣言されたメソッドのいずれかを呼び出すと、インスタンスが YES を返すため、これは奇妙 です。selectableUITextInputTraitsinstance does not respond to selectorUITextViewrespondsToSelector:UITextInputTraits

これは iOS 7 のバグのように思えます。Apple には、rader://15063164 として報告しました。

また、(ストーリーボードではなく) コードを介して作成された UITextView の場合、このバグは表現されないことにも気付きました。理由はまだわかりません。追加のプロパティが動作している可能性や、UITextView がinitWithCoder:ではなく 初期化されているという事実がinitWithFrame:原因で、別の状態になっている可能性があります。

バグを示すいくつかのコード:

@interface IBAViewController ()

@property (strong, nonatomic) IBOutlet UITextView *editableAndSelectable;
@property (strong, nonatomic) IBOutlet UITextView *selectable;
@property (strong, nonatomic) IBOutlet UITextView *notEditableOrSelectable;

@end

@implementation IBAViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    /* 
     Remove the define below and we won't crash on the last NSAssert below.  Leave it in
     and we crash (assuming we've created and connected three UITextView's to the IBOutlets above
     in a storyboard for this view controller).
    */

#define USING_STORYBOARD

#ifndef USING_STORYBOARD
    self.editableAndSelectable = [[UITextView alloc] initWithFrame:self.view.bounds];
    self.selectable = [[UITextView alloc] initWithFrame:self.view.bounds];
    self.notEditableOrSelectable = [[UITextView alloc] initWithFrame:self.view.bounds];

    [self.view addSubview:self.editableAndSelectable];
    [self.view addSubview:self.selectable];
    [self.view addSubview:self.notEditableOrSelectable];
#endif

    self.editableAndSelectable.text = @"Text1";
    self.editableAndSelectable.editable = YES;
    self.editableAndSelectable.selectable = YES;

    self.selectable.text = @"Text2";
    self.selectable.editable = NO;
    self.selectable.selectable = YES;

    self.notEditableOrSelectable.text = @"Text3";
    self.notEditableOrSelectable.editable = NO;
    self.notEditableOrSelectable.selectable = NO;

    NSAssert(self.editableAndSelectable.editable == YES, @"Huh?");
    NSAssert(self.editableAndSelectable.selectable == YES, @"Huh?");

    NSAssert([self.editableAndSelectable respondsToSelector:@selector(isSecureTextEntry)], @"Huh?");
    NSAssert([self.editableAndSelectable isSecureTextEntry] == NO, @"Huh?");

    NSAssert(self.selectable.editable == NO, @"Huh?");
    NSAssert(self.selectable.selectable == YES, @"Huh?");

    NSAssert([self.editableAndSelectable respondsToSelector:@selector(isSecureTextEntry)], @"Huh?");
    NSAssert([self.editableAndSelectable isSecureTextEntry] == NO, @"Huh?");

    NSAssert(self.notEditableOrSelectable.editable == NO, @"Huh?");
    NSAssert(self.notEditableOrSelectable.selectable == NO, @"Huh?");

    NSAssert([self.notEditableOrSelectable respondsToSelector:@selector(isSecureTextEntry)], @"Huh?");
    NSAssert([self.notEditableOrSelectable isSecureTextEntry] == NO, @"Huh?"); // crashes here (on iOS 7)
}

@end

他の誰かがこれを見たことがありますか?または何かアイデアはありますか?

4

0 に答える 0