I have a subclass of a UITextView and I would like to make it it's own delegate. So that I can override the textView:shouldChangeTextInRange:replacementText:
method, and prevent consecutive spaces being entered.
In [SATextView awakeFromNib]
(SATextView is my subclass of UITextView), I do [self setDelegate:self];
. When I press on the textview to start editing everything freezes and eventually stops, and that backtrace shows that there has been an infinite loop.
It doesn't matter if I implement all delegate methods, just one, or none. Nor does it matter if those methods are empty.
Why does this cause an infinite loop? It only seems to happen if with UITextView (other objects you can subclass and set the delegate to self, and it won't have this problem). And how can I stop it? Or is there a better way to have this subclass not able to have consecutive spaces,
An idea... You could make a delegate Class that acts as a middle man between the real delegate and the UITextView (because you'll probably need to set the delegate after some time). So this new class will implement the delegate protocol, but it will also have a property for it's own delegate, so that you can forward textView:shouldChangeTextInRange:replacementText:, and still do the work of editing the spaces in your middleMan class.
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