あなたの見解に依存します。TextField を使用する場合は、以下に示すように、.header ファイルで UITextFieldDelegate をデリゲートとして使用する必要があります。
@interface ExamPageViewController : UIViewController <UITextFieldDelegate>
UITextFieldDelegate メソッドを使用できます。わかります。
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self.questionAnswerTextField resignFirstResponder];
return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if ([textField.text isEqualToString:@"Sorunun cevabını buraya yazınız!"]) {
textField.text = @"";
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if ([textField.text isEqualToString:@""]) {
textField.text = @"Sorunun cevabını buraya yazınız!";
}
}
それ以外の場合は、以下のコード スニペットのように UITextViewDelegate をデリゲートとして使用する必要があります。
@interface ExamPageViewController : UIViewController <UITextViewDelegate>
そして、これらのデリゲート メソッドを .m ファイルで使用することができます
- (BOOL)textViewShouldReturn:(UITextView *)textField {
[self.questionAnswerTextField resignFirstResponder];
return YES;
}
-(void)textViewDidBeginEditing:(UITextView *)textField {
if ([textField.text isEqualToString:@"Sorunun cevabını buraya yazınız!"]) {
textField.text = @"";
}
}
- (void)textViewDidEndEditing:(UITextView *)textField {
if ([textField.text isEqualToString:@""]) {
textField.text = @"Sorunun cevabını buraya yazınız!";
}
}