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

后端 未结 3 1167
一整个雨季
一整个雨季 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];
    }
    
    0 讨论(0)
  • 2021-01-02 01:39

    Problem solved by changing the delegate to the object which inits my text view.

    0 讨论(0)
  • 2021-01-02 01:41

    I solved this by custom customOverlayContainer and return the textFiled. eg.

    @implementation CustomTextField
    
    - (id)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
            self.delegate = self;
        }
        return self;
    }
    
    - (id)customOverlayContainer {
        return self;
    }
    
    @end
    

    Tested on iOS 7 and iOS 6.

    0 讨论(0)
提交回复
热议问题