UITextField delegate jumping to 100% CPU usage and crashing upon using keyboard shortcut

后端 未结 3 1186
一整个雨季
一整个雨季 2021-01-02 00:59

So, I have a UITextField subclass which is it\'s own Delegate and is crashing when keyboard shortcuts are used. It maxes out on CPU an

3条回答
  •  攒了一身酷
    2021-01-02 01:39

    I encountered the same issue today when working with a self-delegating UITextField subclass. If it is not possible to change the delegate to something other than self, I would recommend overriding respondsToSelector rather than implementing a customOverlayContainer method that may return an invalid object (are you sure it's supposed to be an instance of UITextField? How do you know iOS isn't asking for a UIView or a CGLayer or any other type of object?)

    -(BOOL) respondsToSelector:(SEL)aSelector {
    
        NSString * selectorName = NSStringFromSelector(aSelector);
    
        if ([selectorName isEqualToString:@"customOverlayContainer"]) {
    
            NSLog(@"preventing self.delegate == self crash");
    
            return NO;
        }
    
        return [super respondsToSelector:aSelector];
    }
    

提交回复
热议问题