-2

I need to run this set of code:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

in another method (IBAction).

So for example I need to run it like this :

[self performSelector:@selector(textView:shouldChangeTextInRange:replacementText:) withObject:nil afterDelay:0.1];

How may I do that?

Simon
  • 25,468
  • 44
  • 152
  • 266
Nicholas
  • 69
  • 1
  • 9
  • NSInvocation is probably you best option. See http://stackoverflow.com/questions/313400/nsinvocation-for-dummies/3224774#3224774 – Jonathan King Oct 19 '13 at 16:05
  • Why are you wanting to call the UITextView delegate directly? Do you have the range of edited text and replacement text? – bbarnhart Oct 19 '13 at 16:05

1 Answers1

1

You cant pass arguments to perform selector.

You need to encapsulate the data you want to send along into some single Objective C object (e.g. a NSArray, a NSDictionary, some custom Objective C type) and then pass it through the[NSObject performSelector:withObject:afterDelay:]. For your case:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

Something like:

NSArray * arrayOfThingsIWantToPassAlong = 
    [NSArray arrayWithObjects: range, text, nil];

[self performSelector:@selector(fooFirstInput:) 
           withObject:arrayOfThingsIWantToPassAlong  
           afterDelay:15.0];
David Karlsson
  • 9,396
  • 9
  • 58
  • 103