ios - After converting to ARC I am getting "message sent to deallocated instance" -
i creatinng instance of view this...
- (ibaction)findpatienttapped:(id)sender { requestdialogviewcontroller *findpatientviewcontroller = [[requestdialogviewcontroller alloc] initwithnibname:@"requestdialogviewcontroller" bundle:nil]; findpatientviewcontroller.delegate = self; findpatientviewcontroller.autocorrectoff = yes; findpatientviewcontroller.defaultresponse = @""; findpatientviewcontroller.keyboardtype = @"ascii"; findpatientviewcontroller.returnkeytype = @"go"; findpatientviewcontroller.tag = findrequesttag; findpatientviewcontroller.editset = yes; findpatientviewcontroller.titletext = @"find patient"; findpatientviewcontroller.messagetext =@"enter or portion of patient's name..."; findpatientviewcontroller.messagetext2 = @"last name..."; findpatientviewcontroller.messagetext3 = @"first name..."; findpatientviewcontroller.showresponse2 = yes; findpatientviewcontroller.shownavbarsavebutton = no; findpatientviewcontroller.infotextfile = @""; findpatientviewcontroller.view.frame = cgrectmake(280, 230, 480, 300); [self.view addsubview:findpatientviewcontroller.view]; }
the view contains 2 uitextfield fields entry user. worked fine before running convert arc tool. after conversion view crashes when trying enter value in either of 2 fields with...
-[requestdialogviewcontroller respondstoselector:]: message sent deallocated instance
here .h file of uiviewcontroller after running conversion arc tool...
#import <uikit/uikit.h> @protocol requestdialogviewcontrollerdelegate; @interface requestdialogviewcontroller : uiviewcontroller <uitextfielddelegate>{ id<requestdialogviewcontrollerdelegate> __weak delegate; iboutlet uinavigationbar *navbar; iboutlet uitextfield *response; iboutlet uitextfield *response2; iboutlet uilabel *message; iboutlet uilabel *message2; iboutlet uilabel *message3; iboutlet uibutton *savebutton; nstimer *selectalltimer; nsstring *defaultresponse; nsstring *titletext, *infotextfile; nsstring *messagetext, *messagetext2, *messagetext3; nsstring *placeholdertext; nsstring *keyboardtype, *returnkeytype; bool editset, showsavebutton,shownavbarsavebutton, showresponse2, autocorrectoff; int tag; } @property (weak) id<requestdialogviewcontrollerdelegate> delegate; @property (nonatomic, strong)iboutlet uitextfield *response; @property (nonatomic, strong) iboutlet uitextfield *response2; @property (nonatomic, strong)iboutlet uilabel *message; @property (nonatomic, strong)iboutlet uilabel *message2; @property (nonatomic, strong) iboutlet uilabel *message3; @property (nonatomic, strong)iboutlet uibutton *savebutton; @property (nonatomic, strong)nsstring *defaultresponse; @property (nonatomic, strong)nsstring *titletext, *infotextfile; @property (nonatomic, strong)nsstring *messagetext, *messagetext2, *messagetext3; @property (nonatomic, strong)nsstring *placeholdertext; @property (nonatomic, strong)nsstring *keyboardtype, *returnkeytype; @property (nonatomic, strong)iboutlet uinavigationbar *navbar; @property (readwrite)bool editset, showsavebutton, shownavbarsavebutton, showresponse2, autocorrectoff; @property (readwrite)int tag; @property (nonatomic, strong) nstimer *selectalltimer; - (ibaction)savebuttonpressed:(id)sender; - (void)selectall; - (ibaction)editingdidend:(id)sender; @end @protocol requestdialogviewcontrollerdelegate <nsobject> @optional - (void)requestdialogviewdiddismiss:(requestdialogviewcontroller *)controller withresponse:(nsstring*)reqresponse response2:(nsstring*)reqresponse2; @end
here pertenant references in .h file of class creating instance of requestdialog view...
#import "requestdialogviewcontroller.h" @interface orthoviewcontroller : uiviewcontroller <requestdialogviewcontrollerdelegate>{ } - (void)requestdialogviewdiddismiss:(requestdialogviewcontroller *)controller withresponse:(nsstring*)reqresponse response2:(nsstring*)reqresponse2; @end
what need make work under arc? thinking might have how protocol formed.
thanks,
john
**** dan resolved making findpatientviewcontroller property of calling class...
requestdialogviewcontroller *findpatientviewcontroller; @implementation orthoviewcontroller - (ibaction)findpatienttapped:(id)sender { findpatientviewcontroller = [[requestdialogviewcontroller alloc] initwithnibname:@"requestdialogviewcontroller" bundle:nil]; //set properties , add subview } @end
your findpatientviewcontroller
has nothing retaining it, gets deallocated @ end of method create it. then, when in it's view tries call delegate method on crash.
if findpatienttapped
method in view controller should add findpatientviewcontroller
child view controller. if it's in view, need least store findpatientviewcontroller
in property doesn't deallocated while still using it.
your code didn't work before arc, had memory leak.
Comments
Post a Comment