ios - Set FireDate of UILocalNotification based on the (Dynamic) value of Label -


my problem have custom cell contains label. value of label fetched via webservices in time .initially if go static data i.e. e.g.: 10:54 pm, on click of cell should set me reminder of value set on label.and off course should notify me on said time.

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{      cc *cell=(cc*)[tableview cellforrowatindexpath:indexpath];      nsdate *currentdate=[nsdate date];      nsstring *datestr= cell.timelabel.text;      uilocalnotification *localnotification =[[uilocalnotification alloc]init];      nstimezone *gmt = [nstimezone timezonewithabbreviation:@"gmt"];     nsdateformatter *dateformatter = [[nsdateformatter alloc] init];     [dateformatter setlocale:[nslocale currentlocale]];     [dateformatter setdatestyle:nsdateformatternostyle];     [dateformatter settimestyle:nsdateformattershortstyle];     [dateformatter setdateformat:@"hh:mm a"];     [dateformatter settimezone:gmt];      [dateformatter setdateformat:@"yyyy-mm-dd"];     nsstring *prefix=[dateformatter stringfromdate:currentdate];     nsstring *datetofire=[nsstring stringwithformat:@"%@ %@",prefix,datestr];      [dateformatter setdateformat:@"yyyy-mm-dd hh:mm a"];      nslog(@"date %@",[dateformatter datefromstring:datetofire]);       if (localnotification==nil) {         return;     }       localnotification.firedate=[dateformatter datefromstring:datetofire];     localnotification.timezone=[nstimezone defaulttimezone];     localnotification.alertbody=@"good morning dude..!";     localnotification.repeatinterval=0; //the default value 0, means don't repeat.     localnotification.soundname=uilocalnotificationdefaultsoundname;     [[uiapplication sharedapplication]schedulelocalnotification:localnotification];  }    - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     cc *cell = (cc *) [tableview dequeuereusablecellwithidentifier:@"cc"];     if (cell == nil) {         nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"cc" owner:self options:nil];         cell = (cc *) [nib objectatindex:0];     }       return cell; } 

i tried doing this, isn't working.

thank you.

take dynamic array contain values populated webservice , put populated time cell dynamically in cell.in cellforrow method.

i have taken static array given below

time = [[nsmutablearray alloc] initwithobjects:@"5:35 pm",@"4:56 am",@"6:00 pm",@"7:32 am",nil]; 

you have put values in array dynamically u populated data webservice. , reload table.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     cc *cell = (cc *) [tableview dequeuereusablecellwithidentifier:@"cc"];     if (cell == nil) {         nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"cc" owner:self options:nil];         cell = (cc *) [nib objectatindex:0];     }      cell.textlabel.text=[time objectatindex:indexpath.row];      return cell; } 

and in did select method assign fire date array not cell text label

nsstring *datestr=[time objectatindex:indexpath.row]; 

Comments