getting funny bugs here. there stands out? relating moc , nsfetchedresultscontroller. i'm getting exc_bad_access not particular line hard debug.
@implementation routinetableviewcontroller @synthesize routinetableview; @synthesize entered; @synthesize managedobjectcontext; @synthesize fetchedresultscontroller=__fetchedresultscontroller; #pragma mark - view lifecycle - (void)viewdidload { if (managedobjectcontext == nil) { managedobjectcontext = [(curlappdelegate *)[[uiapplication sharedapplication] delegate] managedobjectcontext]; } [super viewdidload]; } - (void)viewdidunload { self.managedobjectcontext = nil; self.entered = nil; self.fetchedresultscontroller = nil; self.routinetableview = nil; [super viewdidunload]; } - (void)dealloc { [__fetchedresultscontroller release]; [managedobjectcontext release]; [routinetableview release]; [entered release]; [super dealloc]; } #pragma mark add event -(void)addroutine { routine *routine = (routine *)[nsentitydescription insertnewobjectforentityforname:@"routine" inmanagedobjectcontext:managedobjectcontext]; routine.name=entered; nserror *error = nil; if (![managedobjectcontext save:&error]) { // handle error. } nslog(@"%@", error); //nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:0]; nsinteger lastsection = [self.routinetableview numberofsections] -1; [self.routinetableview scrolltorowatindexpath:[nsindexpath indexpathforrow:[self.routinetableview numberofrowsinsection:lastsection]-1 insection:lastsection] atscrollposition:uitableviewscrollpositionbottom animated:yes]; [routine release]; [error release]; } -(void)showprompt { alertprompt *prompt = [alertprompt alloc]; prompt = [prompt initwithtitle:@"add workout day" message:@"\n \n please enter title workout day" delegate:self cancelbuttontitle:@"cancel" okbuttontitle:@"add"]; [prompt show]; [prompt release]; } - (void)alertview:(uialertview *)alertview willdismisswithbuttonindex:(nsinteger)buttonindex { if (buttonindex != [alertview cancelbuttonindex]) { entered = [(alertprompt *)alertview enteredtext]; // if(eventsarray && entered) { [self addroutine]; } } } #pragma mark - table view data source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { id <nsfetchedresultssectioninfo> sectioninfo = [[self.fetchedresultscontroller sections] objectatindex:section]; return [sectioninfo numberofobjects]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; //tableviewcell *cell = (tableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; } routine *temproutine = (routine *)[__fetchedresultscontroller objectatindexpath:indexpath]; // [cell settext:temproutine.name]; cell.textlabel.text = temproutine.name; cell.accessorytype = uitableviewcellaccessorydisclosureindicator; return cell; } // override support conditional editing of table view. - (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath { // return no if not want specified item editable. return yes; } -(void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { // delete managed object given index path nsmanagedobjectcontext *context = [self.fetchedresultscontroller managedobjectcontext]; [context deleteobject:[self.fetchedresultscontroller objectatindexpath:indexpath]]; nslog(@"fetched results : \n%@\n",[self.fetchedresultscontroller fetchedobjects]); // commit change. nserror *error = nil; // update array , table view. if (![managedobjectcontext save:&error]) { // handle error. } //[tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:yes]; } } - (void)configurecell:(uitableviewcell *)cell atindexpath:(nsindexpath *)indexpath { nsmanagedobject *managedobject = [self.fetchedresultscontroller objectatindexpath:indexpath]; cell.textlabel.text = [[managedobject valueforkey:@"name"] description]; } #pragma mark - table view delegate - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // navigation logic may go here. create , push view controller. [tableview deselectrowatindexpath:indexpath animated:yes]; routinedaytableviewcontroller *detailviewcontroller = [[routinedaytableviewcontroller alloc] initwithnibname:@"routinedaytableviewcontroller" bundle:nil]; nsmanagedobject *managedobject = [self.fetchedresultscontroller objectatindexpath:indexpath]; detailviewcontroller.title = [[managedobject valueforkey:@"name"] description]; // // // pass selected object new view controller. // [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes]; // [detailviewcontroller release]; detailviewcontroller.theselectedroutine = [__fetchedresultscontroller objectatindexpath: indexpath]; nslog(@"detailviewcontroller.theselectedroutine:%@",detailviewcontroller.theselectedroutine); [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes]; [detailviewcontroller release]; } #pragma mark - fetched results controller - (nsfetchedresultscontroller *)fetchedresultscontroller { if (__fetchedresultscontroller != nil) { return __fetchedresultscontroller; } // create fetch request entity. nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; // edit entity name appropriate. nsentitydescription *entity = [nsentitydescription entityforname:@"routine" inmanagedobjectcontext:self.managedobjectcontext]; [fetchrequest setentity:entity]; // set batch size suitable number. [fetchrequest setfetchbatchsize:20]; // edit sort key appropriate. nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"name" ascending:no]; nsarray *sortdescriptors = [[nsarray alloc] initwithobjects:sortdescriptor, nil]; [fetchrequest setsortdescriptors:sortdescriptors]; // edit section name key path , cache name if appropriate. // nil section name key path means "no sections". nsfetchedresultscontroller *afetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:self.managedobjectcontext sectionnamekeypath:nil cachename:nil]; afetchedresultscontroller.delegate = self; self.fetchedresultscontroller = afetchedresultscontroller; [afetchedresultscontroller release]; [fetchrequest release]; [sortdescriptor release]; [sortdescriptors release]; nserror *error = nil; if (![self.fetchedresultscontroller performfetch:&error]) { /* replace implementation code handle error appropriately. abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. if not possible recover error, display alert panel instructs user quit application pressing home button. */ nslog(@"unresolved error %@, %@", error, [error userinfo]); abort(); } return __fetchedresultscontroller; } #pragma mark - fetched results controller delegate - (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller { [self.routinetableview beginupdates]; } - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id <nsfetchedresultssectioninfo>)sectioninfo atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type { switch(type) { case nsfetchedresultschangeinsert: [self.routinetableview insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangedelete: [self.routinetableview deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; } } - (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath { uitableview *tableview = self.routinetableview; switch(type) { case nsfetchedresultschangeinsert: [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangedelete: [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangeupdate: [self configurecell:[tableview cellforrowatindexpath:indexpath] atindexpath:indexpath]; break; case nsfetchedresultschangemove: [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]withrowanimation:uitableviewrowanimationfade]; break; } } - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller { [self.routinetableview endupdates]; } @end edit: here app delegate.m
@implementation appdelegate @synthesize window=_window; @synthesize rootcontroller; @synthesize excercisenavcontroller; @synthesize managedobjectcontext=__managedobjectcontext; @synthesize managedobjectmodel=__managedobjectmodel; @synthesize persistentstorecoordinator=__persistentstorecoordinator; - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { // override point customization after application launch. [self.window addsubview:rootcontroller.view]; [self.window makekeyandvisible]; return yes; } - (void)applicationwillresignactive:(uiapplication *)application { /* sent when application move active inactive state. can occur types of temporary interruptions (such incoming phone call or sms message) or when user quits application , begins transition background state. use method pause ongoing tasks, disable timers, , throttle down opengl es frame rates. games should use method pause game. */ } - (void)applicationdidenterbackground:(uiapplication *)application { /* use method release shared resources, save user data, invalidate timers, , store enough application state information restore application current state in case terminated later. if application supports background execution, method called instead of applicationwillterminate: when user quits. */ } - (void)applicationwillenterforeground:(uiapplication *)application { /* called part of transition background inactive state; here can undo many of changes made on entering background. */ } - (void)applicationdidbecomeactive:(uiapplication *)application { /* restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface. */ } - (void)applicationwillterminate:(uiapplication *)application { /* called when application terminate. save data if appropriate. see applicationdidenterbackground:. */ } - (void)dealloc { [_window release]; [rootcontroller release]; [excercisenavcontroller release]; [__managedobjectcontext release]; [__managedobjectmodel release]; [__persistentstorecoordinator release]; [super dealloc]; } - (void)savecontext { nserror *error = nil; nsmanagedobjectcontext *managedobjectcontext = self.managedobjectcontext; if (managedobjectcontext != nil) { if ([managedobjectcontext haschanges] && ![managedobjectcontext save:&error]) { /* replace implementation code handle error appropriately. abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. if not possible recover error, display alert panel instructs user quit application pressing home button. */ nslog(@"unresolved error %@, %@", error, [error userinfo]); abort(); } } } #pragma mark - core data stack /** returns managed object context application. if context doesn't exist, created , bound persistent store coordinator application. */ - (nsmanagedobjectcontext *)managedobjectcontext { if (__managedobjectcontext != nil) { return __managedobjectcontext; } nspersistentstorecoordinator *coordinator = [self persistentstorecoordinator]; if (coordinator != nil) { __managedobjectcontext = [[nsmanagedobjectcontext alloc] init]; [__managedobjectcontext setpersistentstorecoordinator:coordinator]; } return __managedobjectcontext; } /** returns managed object model application. if model doesn't exist, created application's model. */ - (nsmanagedobjectmodel *)managedobjectmodel { if (__managedobjectmodel != nil) { return __managedobjectmodel; } nsurl *modelurl = [[nsbundle mainbundle] urlforresource:@"temp" withextension:@"momd"]; __managedobjectmodel = [[nsmanagedobjectmodel alloc] initwithcontentsofurl:modelurl]; return __managedobjectmodel; } /** returns persistent store coordinator application. if coordinator doesn't exist, created , application's store added it. */ - (nspersistentstorecoordinator *)persistentstorecoordinator { if (__persistentstorecoordinator != nil) { return __persistentstorecoordinator; } nsurl *storeurl = [[self applicationdocumentsdirectory] urlbyappendingpathcomponent:@"temp.sqlite"]; nserror *error = nil; __persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:[self managedobjectmodel]]; if (![__persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:nil error:&error]) { /* replace implementation code handle error appropriately. abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. if not possible recover error, display alert panel instructs user quit application pressing home button. typical reasons error here include: * persistent store not accessible; * schema persistent store incompatible current managed object model. check error message determine actual problem was. if persistent store not accessible, there typically wrong file path. often, file url pointing application's resources directory instead of writeable directory. if encounter schema incompatibility errors during development, can reduce frequency by: * deleting existing store: [[nsfilemanager defaultmanager] removeitematurl:storeurl error:nil] * performing automatic lightweight migration passing following dictionary options parameter: [nsdictionary dictionarywithobjectsandkeys:[nsnumber numberwithbool:yes], nsmigratepersistentstoresautomaticallyoption, [nsnumber numberwithbool:yes], nsinfermappingmodelautomaticallyoption, nil]; lightweight migration work limited set of schema changes; consult "core data model versioning , data migration programming guide" details. */ nslog(@"unresolved error %@, %@", error, [error userinfo]); abort(); } return __persistentstorecoordinator; } #pragma mark - application's documents directory /** returns url application's documents directory. */ - (nsurl *)applicationdocumentsdirectory { return [[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] lastobject]; } @end
if have exec_bad_access should turn on zombies , rerun app can see on released;
once know what's on released have better idea of going on.
Comments
Post a Comment