iOS 7:UITextView UITextInputTraits错误?

时间:2013-09-24 08:59:00

标签: ios uitextview uitextinputtraits

今天在Reveal工作时,我发现了iOS 7 UITextView中的一个错误 处理UITextInputTraits协议。

UITextInputTraits协议具有设置键盘类型的方法 当用户点击UITextView和其他此类内容时,应显示该内容。

iOS 7还在selectable上引入了一个新的UITextView属性来控制是否 文本选择已启用。这比以前的方法要好得多 iOS版本,你必须继承UITextView并返回no canBecomeFirstResponder或者设置inputDelegate和 处理适当的委托回调以停止选择发生。

不幸的是,在iOS 7中将editableselectable设置为NO会打破所有问题 UITextInputTraits方法。如果您尝试呼叫其中任何一个,您的应用程序将崩溃 instance does not respond to selector例外。这很奇怪,因为 UITextView实例如果您为任何一个调用respondsToSelector:,将返回YES 在UITextInputTraits协议中声明的方法。

在我看来这是iOS 7中的一个错误。我已经向Apple报告了它作为雷达:// 15063164。

我也注意到UITextView是通过代码(而不是在Storyboards中)创建的 不表达。我不知道为什么。工作中可能还有其他属性或 事实是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

有没有人见过这个?或者有什么想法?

0 个答案:

没有答案