ios - UITextField textInputView message sent to deallocated instance -
i have crashes occur when tap on uitextfield. have 2 controllers, let's a , b. when show controller b modally in controller a, , tap on uitextfield ok. dismiss controller b, , present again. time when click on uitextfield crash occurs. when enabled nszombie in scheme, there message of crash - -[uitextfield textinputview]: message sent deallocated instance
.
i have no uitextfielddelegate
set on uitextfield. when tried debug instruments -> zombies, there no source code (unavailable) when double click release/retain history line.
my scheme's build configuration debug. xcode version 7.2.1. crashes occur on ios 8. ios 9 fine.
ps: when try re-symbolicate app, see there 1 missing system frameworks dyld. press locate button , open dsym file of debug app, error occurs message "the specified path didn't locate dsym of selected libraries."
update 1:
a controller:
#import <uikit/uikit.h> @interface : uiviewcontroller @end #import "a.h" #import "roundedbutton.h" @interface () @property (weak, nonatomic) iboutlet roundedbutton *signinbutton; @end @implementation - (void)viewdidload { [super viewdidload]; [self configui]; } - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; [[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstyledefault animated:yes]; [self.navigationcontroller setnavigationbarhidden:yes animated:yes]; } - (uistatusbarstyle)preferredstatusbarstyle { return uistatusbarstyledefault; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - segue - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"signin"]) { } } #pragma mark - config ui - (void)configui { // setup ui } - (void)dealloc { nslog(@"%@ deallocated", nsstringfromclass([self class])); } @end
b controller:
#import <uikit/uikit.h> @interface b : uiviewcontroller @end #import "b.h" #import "skformtextfield.h" #import "roundedbutton.h" @interface b () @property (weak, nonatomic) iboutlet uitextfield *textfield; @property (weak, nonatomic) iboutlet roundedbutton *signinbutton; @end @implementation b { skalertview *alertview; } - (void)viewdidload { [super viewdidload]; [self configui]; } - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; } #pragma mark - actions - (ibaction)cancelsignin:(id)sender { [self dismissviewcontrolleranimated:yes completion:nil]; } #pragma mark - config ui - (void)configui { self.navigationcontroller.navigationbarhidden = yes; self.textfield.securetextentry = true; self.textfield.autocorrectiontype = uitextautocorrectiontypeno; } - (void)dealloc { nslog(@"%@ deallocated", nsstringfromclass([self class])); } @end
update 2:
when call uitextfield
, self.textfield.text = @"hello, world!";
, there no crash. when pan/touch uitextfield
or call [self.textfield becomefirstresponder];
crashes.
finally, found reason of crashes. have uitextfield
extension called uitextfield (autosuggestion)
called dealloc method remove own observers.
code sample:
/* .h file */ #import <uikit/uikit.h> // protocol @interface uitextfield (autosuggestion) // properties , methods @end /* .m file */ #import "uitextfield+autosuggestion.h" #import <objc/runtime.h> @implementation uitextfield (autosuggestion) - (void)observetextfieldchanges { self.layer.maskstobounds = no; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(toggleautosuggestion:) name:uitextfieldtextdidchangenotification object:self]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(hideautosuggestion) name:uitextfieldtextdidendeditingnotification object:self]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(getkeyboardheight:) name:uikeyboarddidshownotification object:nil]; } - (void)dealloc { [[nsnotificationcenter defaultcenter] removeobserver:self name:uitextfieldtextdidchangenotification object:nil]; [[nsnotificationcenter defaultcenter] removeobserver:self name:uitextfieldtextdidendeditingnotification object:nil]; [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboarddidshownotification object:nil]; } // other methods @end
after removed dealloc
method crashes disappeared. therefore decided find new way implement autosuggestion feature.
the interesting thing didn't import header file in code anywhere, crashes occurred.
Comments
Post a Comment