I am using this code to set the parameters of an uitextview i have on my view.
_textview=[[UITextView alloc]init];
[_textview setUserInteractionEnabled:FALSE];
_textview.text=@"Write your message";
_textview.textColor=[UIColor lightGrayColor];
_textview.layer.cornerRadius=6;
_textview.contentInset = UIEdgeInsetsZero;
_textview.delegate=self;
I have in the .h this code
IBOutlet UITextView *_textview;
@property(nonatomic,retain) IBOutlet UITextView *_textview;
I have connected the outlet to the uitextview by using the interface.
What happens is the following:
- (void)textViewDidChange:(UITextView *)inTextView
the above delegate is called but not the following one:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string
Why is this happening? Am i doing something wrong?
Any help appreciated...
In addition to removing the _textview = [[UITextView alloc]init];
so as to not overwrite your nib loaded textview.
The <UITextViewDelegate>
method is:
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{}
The correct method signature is:
textView:shouldChangeTextInRange:replacementText:
not:
textView:shouldChangeTextInRange:replacementString:
Because you are typing the method name wrong.
There is no
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string
but only
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
careful with the different between replacementString
and replacementText
.
Also, as the others said, if you've created the UITextView in IB, you should NOT init it again in your code (but this is not the reason why your delegate never invoked).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With