[英]Tap on UITextField's clear button hides keyboard instead of clearing text
[英]Clear the content of the UITextField's text property for tap
我有一個名為place
的UITextField,它的text屬性包含一個NSString
。 當用戶點擊文本字段時,我想從text屬性中清除現有內容。
我嘗試了上面的代碼,但沒有任何反應。 我也嘗試使用占位符屬性,但這是相同的。 您知道可能是什么問題嗎? 我認為應該可以。
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.place.text = nil;
}
2,版本-在這種情況下,從頭開始在文本字段中什么都沒有出現
- (void)viewDidLoad
{
[super viewDidLoad];
...
[self textFieldDidBeginEditing:place];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
textField.text = nil;
}
您可以通過編程將屬性clearsOnBeginEditing
設置為YES
或者在Interface Builder中有一個復選框。
如果您還想清除占位符
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.placeholder = nil;
}
仔細檢查UITextField
self.place是否已將其委托設置為視圖控制器,並驗證是否正在調用textFieldDidBeginEditing
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.