0

In my application there is UITextView containing an email address. When I touch and hold on email address, then an action sheet pops up with following buttons on it:

  • "New message"
  • "Add to contact"
  • etc.

How to perform custom action on "New message" button click?

jszumski
  • 7,430
  • 11
  • 40
  • 53
Ram
  • 52
  • 8
  • I don't think you can intercept this action sheet. As you mention it's an OS generated action sheet, so you can't set any of your objects as its delegate. You either have it as is, or turn off link detection. – Ian L Apr 18 '13 at 11:34

3 Answers3

2

First you implement UIActionSheetDelegate in your .h file and then do it..

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        // here you can perform new message action
    }
    else
    {
        // here you can perform add new contact action
    }
}
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
1

You have to set your viewController as the actionSheets delegate and then implement

-actionSheet:clickedButtonAtIndex:

Then perform the action you need.

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107
  • This delegate method not calling because action sheet generated by iOS , not by my application. – Ram Apr 18 '13 at 11:28
1

You'll need to subclass UITextView and overwrite the -setText: method. In your custom implementation you will need to add UIDataDetector to your subclass.

If you'r not familiar with NSDataDetector and its implementation, take a look at the implementation of TTTAttributedLabel. It is a quite full-blown replacement for UILabel with data detection and a very well developed delegate protocol.

You could adopt pretty much of its code.

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107