在 iOS 模拟器中使用“Command+delete”从 UITextView 中删除文本后,我无法再为 UITextView 设置任何文本。
textView.text = @"any text"; //no longer works
因为文本会被 UITextView 自动删除,如果我通过键盘输入,一切都OK了。
这是代码,很简单。
@interface ViewController ()
@property (nonatomic,strong) UITextView *textView;
@end
@implementation ViewController
-(void)loadView{
[super loadView];
self.textView = [[UITextView alloc] initWithFrame:self.view.frame];
[self.view addSubview:self.textView];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
button.backgroundColor = [UIColor blackColor];
[button setTitle:@"setText" forState:UIControlStateNormal];
button.center = self.view.center;
[button addTarget:self action:@selector(setText) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)setText{
self.textView.text = @"any text";
}