[英]how can i detect date from UITextView and add an event as you tap it
我可以從UITextView
檢測日期並在單擊時添加事件。 文本視圖不處於可編輯模式。 我試過了
self.txtView.dataDetectorTypes = UIDataDetectorTypeAll;
但它不起作用,請幫助我
您可以UITapGestureRecogniser
這種方式添加UITapGestureRecogniser
。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)];
singleTap.numberOfTapsRequired = 1;
[self.txtView addGestureRecognizer:singleTap];
}
-(void)doSingleTap:(UITapGestureRecognizer *)recognizer
{
// ----- do here........
}
您在應用程序中鍵入什么假設日期? 如果它們過去,則不會檢測到它們。
日期必須是將來的日期。
而且,這與是否有輕擊手勢識別器無關。 您只需要確保它不在可編輯模式下即可,但是您可以這樣做。
我的解決方案只是通過按鈕將編輯模式和dataDetectorTypes
切換為“ All
或“ None
。 您可以根據需要將其設置為UIDataDetectorTypeCalenderEvent
。
例如:
- (IBAction)didTapEditButton:(id)sender {
if (self.noteText.editable == NO) {
[self.editButton setTitle:@"Done" forState:UIControlStateNormal];
self.noteText.dataDetectorTypes = UIDataDetectorTypeNone;
self.noteText.editable = YES;
} else {
[self.editButton setTitle:@"Edit" forState:UIControlStateNormal];
self.noteText.editable = NO;
self.noteText.dataDetectorTypes = UIDataDetectorTypeAll;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.