开发者

(Objective-c) Text View "Clear When editing starts"

Is it possible to add Clear when editing starts to a text view? This option is available for the text field but I 开发者_JS百科couldn't find anything for the text view.

Thanks!


Implement the UITextViewDelegate method called textViewDidBeginEditing:, and inside of it, set the text property to an empty NSString object:

- (void) textViewDidBeginEditing:(UITextView *) textView {
  [textView setText:@""];
  //other awesome stuff here...
}


above did not work for me, had to use notifications:

add notification in viewWillAppear:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textViewDidBeginEditing:) name:UITextViewTextDidBeginEditingNotification object:nil];

method to clear the current text view

-(void)textViewDidBeginEditing:(NSNotification *)notif{
UITextView *textView=notif.object;
textView.text=@"";

}

remove notification in viewWillDisappear:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidBeginEditingNotification object:nil];

Hope it helps somebody

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜