user709877
user709877

Reputation: 69

Which delegate method will get fired in UITextfield or UITextview?

I want to know which delegate method will get fired when we long press the UITextfield or UITextview to move the cursor? Please help me out.

Upvotes: 0

Views: 1453

Answers (2)

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

You should use the Gesture Recognizer for this purpose

1)Firstly Add Recognizer to your TextFiled

**-(void)viewDidLoad{**

    UILongPressGestureRecognizer *recognizerTextFiled = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandlerGurmukhiFirstSearch:)];

    recognizerTextFiled.minimumPressDuration = 0.5;

    //after this time Recognizer will invoke   

    // here i have added the Recognizer to that textField

    // myTextFiled is a textField at which we want to detect the cursor movement

     [myTextFiled addGestureRecognizer:recognizerTextFiled];

     [recognizerTextFiled release];      
    }

2) You may Write Your Logic after detecting the Cursor Movement As Below

**-(void)longPressHandlerGurmukhiFirstSearch:(UILongPressGestureRecognizer *)gestureRecognizer**
 {           
       if(UIGestureRecognizerStateBegan ==gestureRecognizer.state)
         {
  // you can write the code here as you want for moving the Cursor
        }

if(UIGestureRecognizerStateChanged == gestureRecognizer.state) {
            // Do repeated work here (repeats continuously) while finger is down
      }

  if(UIGestureRecognizerStateEnded == gestureRecognizer.state) {
            // Do end work here when finger is lifted
        }
    }
}

I Hope This would help you to detecting the cursor movement over UITextField

Upvotes: 0

jrturton
jrturton

Reputation: 119292

There is no suitable UITextField delegate for detecting cursor movements.

You may be able to use textViewDidChangeSelection: when working with a UITextView, see here.

Upvotes: 1

Related Questions