ios - Simulator not getting location -
i'm following this tutorial learn core data. i'm on section 4, adding events. in section 2 tutorial says add button become active seconds after prompted simulator location, never becomes active, idea might happening?
ps: if hardcode button active before getting location following error:
*** terminating app due uncaught exception 'nsrangeexception', reason: '*** -[nsmutablearray objectatindex:]: index 0 beyond bounds empty array'
on following line:
[self.tableview insertrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];
edit: posting more code bigger picture
- (void)viewdidload { [super viewdidload]; self.title = @"locations"; self.navigationitem.leftbarbuttonitem = self.editbuttonitem; addbutton = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self action:@selector(addevent)]; addbutton.enabled = no; self.navigationitem.rightbarbuttonitem = self.addbutton; [[self locationmanager] startupdatinglocation]; eventsarray = [[nsmutablearray alloc] init]; }
this method there error:
-(void)addevent{ cllocation *location = [locationmanager location]; if(location){ return; } event *event = (event *)[nsentitydescription insertnewobjectforentityforname:@"event" inmanagedobjectcontext:managedobjectcontext]; cllocationcoordinate2d coordinate = [location coordinate]; event.latitude = [nsnumber numberwithfloat:coordinate.latitude]; event.longitude = [nsnumber numberwithfloat:coordinate.longitude]; event.creationdate = [nsdate date]; nserror *error; if (![managedobjectcontext save:&error]) { } [eventsarray insertobject:event atindex:0]; nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:0]; [self.tableview insertrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; [self.tableview scrolltorowatindexpath:[nsindexpath indexpathforrow:0 insection:0] atscrollposition:uitableviewscrollpositiontop animated:yes]; }
and appdidlaunch method:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { rootviewcontroller *rootviewcontroller = [[rootviewcontroller alloc] initwithstyle:uitableviewstyleplain]; navigationcontroller = [[uinavigationcontroller alloc] init]; nsmanagedobjectcontext *context = [self managedobjectcontext]; if(!context){ } rootviewcontroller.managedobjectcontext = context; [self.navigationcontroller pushviewcontroller:rootviewcontroller animated:no]; [rootviewcontroller release]; [self.window addsubview:navigationcontroller.view]; [self.window makekeyandvisible]; return yes; }
there no nsmutablearray
in code posted. problem error trying access object (at index 0
) in empty nsmutablearray
. find array, , find problem.
Comments
Post a Comment