Search code examples
iosobjective-cuiactionsheet

How to listen action on iOS generated action sheet


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?


Solution

  • 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
        }
    }