This is the weirdest thing I've ever encountered, and the problem is consistent across an iPhone 4 and iPhone 5s...
I've created a subclass of UITextField to add some custom functionality, and have set a UITextField's custom class to my custom class in the storyboard.
Great, all good - but.. Anytime I tap to open the field, I can type fine - as soon as I hit the emoji globe part of the keyboard, the app instantly locks up. It doesn't crash, I just cannot do anything, the typing indicator stops blinking and the app just hangs infinitely..
So very strange.
Here's the custom class I've created.
Header
#import <UIKit/UIKit.h>
@interface GenericTextField : UITextField <UITextFieldDelegate>
@property id nextField;
@property id nextCallbackTarget;
@property SEL nextCallbackSelector;
@end
Implementation
#import "GenericTextField.h"
@implementation GenericTextField
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self setup];
}
return self;
}
- (void)setup
{
self.delegate = self;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([self.nextField respondsToSelector:@selector(becomeFirstResponder)]) {
[self.nextField becomeFirstResponder];
} else {
[self resignFirstResponder];
if ([self.nextCallbackTarget respondsToSelector:self.nextCallbackSelector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.nextCallbackTarget performSelector:self.nextCallbackSelector];
#pragma clang diagnostic pop
}
}
return NO;
}
@end
Here's another interesting part. If I comment out the portion where I'm setting the delegate to self, everything works fine.. However, if I comment out my custom delegate methods and keep the delegate set to self in the setup method, I still get the freeze. This seems to be specifically linked to setting the delegate? Why? Does it have to do with setting it to self from the initWithCoder? If so, why does it just happen in UITextField and none of my other custom classes that set delegates to self like in a UIScrollView subclass I've made?