iphone - My UITextView makes my App crash when back button is pressed to get back to the menu in Xcode -
this code have in .h
@interface notebook : uiviewcontroller { iboutlet uitextview *textview; //loads "data saved" message after save button hit iboutlet uilabel *loaded; } //database actions - (ibaction)save:(id)sender; @end and here code in .m
@implementation notebook { } //saves loaded data - (ibaction)save:(id)sender { //first save string nsstring *savestring = textview.text; nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults setobject:savestring forkey:@"savestring"]; [defaults synchronize]; //shows saved data message loaded.text = @"data saved"; } - (void)viewdidload { [super viewdidload]; //automatically loads data on re-enter of screen nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; nsstring *loadstring = [defaults objectforkey:@"savestring"]; [textview settext:loadstring]; // additional setup after loading view nib. } - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [[event alltouches] anyobject]; if ([textview isfirstresponder] && [touch view] != textview) { [textview resignfirstresponder]; } [super touchesbegan:touches withevent:event]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
Comments
Post a Comment