Délégué UITextField sautant à 100% d'utilisation du processeur et se brisant sur l'utilisation du raccourci keyboard

Donc, j'ai une sous-class UITextField qui est son propre Delegate et plante quand des raccourcis keyboard sont utilisés. Il maximise sur le CPU et ne donne pas une erreur. Sans s'atsortingbuer comme Delegate , cela fonctionne sans problème. Lorsqu'il est affecté comme Delegate , il se bloque même si vous n'utilisez aucune des methods (facultatives).

Essayez-le vous-même:

Sous-class UITextField .

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

Il devrait tomber en panne.

EDIT Backtrace:

 * thread #1: tid = 0x3bb8d, 0x39f14726 libobjc.A.dylib`lookUpImpOrNil + 18, queue = 'com.apple.main-thread, stop reason = signal SIGSTOP frame #0: 0x39f14726 libobjc.A.dylib`lookUpImpOrNil + 18 frame #1: 0x39f0dcb6 libobjc.A.dylib`class_respondsToSelector + 34 frame #2: 0x39f1d05c libobjc.A.dylib`-[NSObject respondsToSelector:] + 32 frame #3: 0x323b9242 UIKit`-[UITextField respondsToSelector:] + 46 frame #4: 0x325c88a2 UIKit`-[UITextField customOverlayContainer] + 50 frame #5: 0x325c8730 UIKit`-[UITextField automaticallySelectedOverlay] + 28 frame #6: 0x32554208 UIKit`-[UIKeyboardImpl inputOverlayContainer] + 424 frame #7: 0x32553942 UIKit`-[UIKeyboardImpl _autocorrectPromptRects] + 454 frame #8: 0x323c7530 UIKit`-[UIKeyboardImpl updateAutocorrectPrompt:] + 368 frame #9: 0x323e63e0 UIKit`-[UIDelayedAction timerFired:] + 80 frame #10: 0x305fbe6c Foundation`__NSFireTimer + 64 frame #11: 0x2fbe1e86 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14 frame #12: 0x2fbe1aa2 CoreFoundation`__CFRunLoopDoTimer + 794 frame #13: 0x2fbdfe2a CoreFoundation`__CFRunLoopRun + 1218 frame #14: 0x2fb4a540 CoreFoundation`CFRunLoopRunSpecific + 524 frame #15: 0x2fb4a322 CoreFoundation`CFRunLoopRunInMode + 106 frame #16: 0x348812ea GraphicsServices`GSEventRunModal + 138 frame #17: 0x324011e4 UIKit`UIApplicationMain + 1136 frame #18: 0x0009929c Today`main(argc=1, argv=0x27d79c80) + 164 at main.m:29 

J'ai rencontré le même problème aujourd'hui lorsque je travaillais avec une sous-class UITextField auto- UITextField . S'il n'est pas possible de changer le délégué en quelque chose d'autre que self, je vous recommand de customOverlayContainer plutôt que d'implémenter une méthode customOverlayContainer qui peut renvoyer un object invalide (êtes-vous sûr qu'il s'agit d'une instance de UITextField ? ne request pas un UIView un CGLayer ou tout autre type d'object?)

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

Problème résolu en changeant le délégué à l'object qui init mon affichage de text.

J'ai résolu ceci par CustomOverlayContainer personnalisé et renvoyer le textFiled. par exemple.

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

Testé sur iOS 7 et iOS 6.