简体   繁体   中英

how can i detect date from UITextView and add an event as you tap it

Can i detect date from UITextView and add an event as you tap it. The text view is not in editable mode. I tried

self.txtView.dataDetectorTypes = UIDataDetectorTypeAll;

but its not working please help me

You can add UITapGestureRecogniser in this way..

- (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........
}

What hypothetical dates are you typing in your application? If they are in the past it won't detect them.

The dates must be future dates.

Also, it's not about whether there is a tap gesture recognizer or not. You just have to make sure it's not in editable mode, however you do that.

My solution just toggles editing mode and dataDetectorTypes to All or None as appropriate via a button. You can set yours to just UIDataDetectorTypeCalenderEvent if you like.

For Example:

- (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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM