每当用户点击返回键或开始在 Xcode 中的 UITextView 上输入时,我都尝试插入当前日期/时间,但不太确定从哪里开始。
我知道此方法适用于单击 TextView 但似乎不起作用:
- (void)textViewDidBeginEditing:(UITextView *)textView {
self.txtDetail.text = [self.txtDetail.text stringByAppendingString:@"Hello!"];
}
谢谢
更新:
DetailViewController.h
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {
UITextView *txtDetail;
}
@property (nonatomic, retain) IBOutlet UITextView *txtDetail;
- (void)textViewDidBeginEditing:(UITextView *)textView;
DetailViewController.m
@synthesize txtDetail;
- (void)textViewDidBeginEditing:(UITextView *)textView {
NSLog(@"Hello");
self.txtDetail.text = [self.txtDetail.text stringByAppendingString:@"Hello!"];
}
更新02:
我已将此添加到我的 .m 文件中:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
BOOL shouldChangeText = YES;
if ([text isEqualToString:@"\n"]) {
// Find the next entry field
txtDetail.text = [txtDetail.text stringByAppendingString:@"\nhey\n"]; }
textView.editable = YES;
shouldChangeText = NO;
[textView becomeFirstResponder];
return shouldChangeText;
}
我得到了想要的效果(嘿,每当我在键盘上按回车键时都会添加)但我现在什么都不能输入......有什么想法吗?