Trigger an action tapping a textview

Discussion in 'iOS Programming' started by Alhazred, Jul 13, 2011.

  1. macrumors member

    Joined:
    Jul 5, 2011
    #1
    Is there a way to trigger an action when a user taps inside a textview area?
    I know that I could put an invisible button on it, but that makes impossible to scroll the text.
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Quite easy..
    You have delegate methods on your UITextView (UITextViewDelegate).
    TextviewDidBeginEditing (or something similair, i'll leave it up to you to find that out.).
    THen trigger a action there..
    for eg.
    [self doMethod1];
    or do a performSelector after Delay 4.

    You're smart enough to find the rest out.
     
  3. thread starter macrumors member

    Joined:
    Jul 5, 2011
    #3
    Here what I've done, but with no luck:
    int the nib file I've linked the UIView as delegate for the textview

    I've declared my view conltroller in this way
    @interface PickItemDetailViewController : UIViewController <UITextViewDelegate> {

    then in the .m file I've put
    - (void)textViewDidBeginEditing:(UITextView *)textView {
    NSLog(@"textViewDidBeginEditing");
    }

    but nothing appears inside the console.

    Do I miss anything?
     
  4. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    You don't need to link the UIView as a delegate, because, it's the textView that you need as delegate..
    you can set it in your code too. if you added the delegate (in your header file).

    You can just do this

    myTextView.delegate = self (in your viewDidLoad).

    And then it should be triggered (if the correct myTextView is connected via IB), in other words -->
    IBOutlet myTextView *myTextView;
     
  5. thread starter macrumors member

    Joined:
    Jul 5, 2011

Share This Page