iphone - NSString out of scope problem? -
i'm pulling hair out, must simple problem, can't see it.
i'm trying assign value variable text field.
in h file have
nsstring *currentpass; @property (nonatomic, retain) nsstring *currentpass;
my m file.
@synthesize currentpass; - (void)alertview:(uialertview *)alertview willdismisswithbuttonindex: (nsinteger)buttonindex{ if (alertview.tag == alertpasswordask) { uitextfield* thetextfield = ((uitextfield*)[alertview viewwithtag: 5]); currentpass = [nsstring stringwithformat:@"%@", thetextfield.text]; if ([thetextfield isediting]) { [thetextfield resignfirstresponder]; } } } - (void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex{ nslog(@"diddismisswithbuttonindex tag=%i", alertview.tag); if (alertview.tag == alertpasswordask) { if(buttonindex == 1){ nsuserdefaults *mydefaults = [nsuserdefaults standarduserdefaults]; nsstring *strpassword = [nsstring alloc]; strpassword = [mydefaults stringforkey:@"pass"]; // ######### error occurs here ######### nslog(@"currentpass=%@ strpassword=%@", currentpass, strpassword); if (![currentpass isequaltostring:strpassword]) {
[6337:207] diddismisswithbuttonindex tag=10 current language: auto; objective-c (gdb) continue program received signal: “exc_bad_access”. (gdb) bt #0 0x02894903 in objc_msgsend () #1 0x00000000 in ?? ()
you need retain object assign currentpass
:
self.currentpass = [nsstring stringwithformat:@"%@", thetextfield.text];
Comments
Post a Comment