ios - Apple iWatch: contexts not sending between view controllers -
so i'm building calendar-type app on new apple iwatch. initial storyboard layout app:
basically initial table view parse calendar , grab event name , date of it. want basically, through push segue, send data second view controller.
i have tried using method -(nsarray *)contextsforseguewithidentifier:(nsstring *)segueidentifier
, context in second view controller showing nil
.
this code:
interfaceviewcontroller:
#import "interfacecontroller.h" #import <eventkit/eventkit.h> #import "calendar.h" @interface interfacecontroller() { nsarray *events; nsarray *eventswithnotes; } @end @implementation interfacecontroller - (void)setuptable { ekeventstore *store = [[ekeventstore alloc] init]; // appropriate calendar nscalendar *calendar = [nscalendar currentcalendar]; if ([store respondstoselector:@selector(requestaccesstoentitytype:completion:)]) { [store requestaccesstoentitytype:ekentitytypeevent completion:^(bool granted, nserror *error) { if (granted) { nslog(@"user has granted permission!"); // create start date components nsdatecomponents *onedayagocomponents = [[nsdatecomponents alloc] init]; onedayagocomponents.day = -1; nsdate *onedayago = [calendar datebyaddingcomponents:onedayagocomponents todate:[nsdate date] options:0]; // create end date components nsdatecomponents *oneyearfromnowcomponents = [[nsdatecomponents alloc] init]; oneyearfromnowcomponents.year = 1; nsdate *oneyearfromnow = [calendar datebyaddingcomponents:oneyearfromnowcomponents todate:[nsdate date] options:0]; // create predicate event store's instance method nspredicate *predicate = [store predicateforeventswithstartdate:onedayago enddate:oneyearfromnow calendars:nil]; // fetch events match predicate events = [store eventsmatchingpredicate:predicate]; nsmutablearray *rowtypeslist = [nsmutablearray array]; for(int i=0; < events.count; i++){ [rowtypeslist addobject:@"calendar"]; } [self.tableview setrowtypes:rowtypeslist]; (nsinteger = 0; < self.tableview.numberofrows; i++) { nsobject *row = [self.tableview rowcontrolleratindex:i]; calendar *calendar = (calendar *) row; nslog(@"notes: %@",[[events objectatindex:i] notes]); nsstring* notes = [[events objectatindex:i] notes]; [calendar.titlelabel settext:[[events objectatindex:i] title]]; } } else { nslog(@"user has not granted permission!"); } }]; } } - (void)awakewithcontext:(id)context { [super awakewithcontext:context]; // configure interface objects here. } - (void)willactivate { // method called when watch view controller visible user [super willactivate]; [self setuptable]; } - (void)diddeactivate { // method called when watch view controller no longer visible [super diddeactivate]; } - (nsarray *)contextsforseguewithidentifier:(nsstring *)segueidentifier intable:(wkinterfacetable *)table rowindex:(nsinteger)rowindex { nsarray *array = nil; nsstring *notes = [[events objectatindex:rowindex] notes]; nsstring *title = [[events objectatindex:rowindex] title]; nsstring *strippednumber = [notes stringbyreplacingoccurrencesofstring:@"[^0-9]" withstring:@"" options:nsregularexpressionsearch range:nsmakerange(0, [notes length])]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdatestyle:nsdateformattermediumstyle]; nsstring *date = [dateformatter stringfromdate:[[events objectatindex:rowindex] startdate]]; if([segueidentifier isequaltostring:@"ibm"]) { array = @[notes, title, strippednumber, date]; } return array; } @end
detailintefaceviewcontroller.h:
#import <watchkit/watchkit.h> #import <foundation/foundation.h> @interface detailinterfacecontroller : wkinterfacecontroller @property (nonatomic, strong) nsstring *currentcontext; @property (weak, nonatomic) iboutlet wkinterfacelabel *phonenumber; @end
detailintefaceviewcontroller.m:
#import "detailinterfacecontroller.h" @interface detailinterfacecontroller () @end @implementation detailinterfacecontroller - (void)awakewithcontext:(id)context { [super awakewithcontext:context]; nslog(@"%@",context); self.currentcontext = context; // configure interface objects here. } - (void)willactivate { // method called when watch view controller visible user [super willactivate]; nslog(@"%@ willactivate",self.currentcontext); [self.phonenumber settext:self.currentcontext]; } - (void)diddeactivate { // method called when watch view controller no longer visible [super diddeactivate]; nslog(@"%@ diddeactivate",self.currentcontext); } @end
any appreciated.
you don't need contextsforseguewithidentifier
method. after setting table, use method.
- (void)table:(wkinterfacetable *)table didselectrowatindex:(nsinteger)rowindex { nsstring *notes = [[events objectatindex:rowindex] notes]; nsstring *title = [[events objectatindex:rowindex] title]; nsstring *strippednumber = [notes stringbyreplacingoccurrencesofstring:@"[^0-9]" withstring:@"" options:nsregularexpressionsearch range:nsmakerange(0, [notes length])]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdatestyle:nsdateformattermediumstyle]; nsstring *date = [dateformatter stringfromdate:[[events objectatindex:rowindex] startdate]]; //you can push controller instead of segue , sending variable data dictionary in context, [self pushcontrollerwithname:@"nibidentifier" context:[nsdictionary dictionarywithobjectsandkeys:notes,@"notes",title,@"title",strippednumber,@"strippednumber",date,@"date",nil]]; }
replace "nibidentifier" specific identifier storyboard.
retrieve data in controller context using this,
- (void)awakewithcontext:(id)context { [super awakewithcontext:context]; nslog(@"%@",[context objectforkey:@"key1"]); nslog(@"%@",[context objectforkey:@"key2"]); nslog(@"%@",[context objectforkey:@"key3"]); nslog(@"%@",[context objectforkey:@"key4"]); }
Comments
Post a Comment