iphone - Array goes empty in DidSelectRowAtIndexPath -
i have in coredatabase entity "day". in method fetch data entity , put in mutuablearray dayobjects. can see code on here.
nsmanagedobjectcontext *context = [rkmanagedobjectstore defaultstore].persistentstoremanagedobjectcontext; nsfetchrequest *fetchrequest = [nsfetchrequest fetchrequestwithentityname:@"day"]; nspredicate *predicate = [nspredicate predicatewithformat: @"p_date >= %@ , p_date <= %@",datestring,datestring2]; [fetchrequest setpredicate:predicate]; nssortdescriptor *descriptor = [nssortdescriptor sortdescriptorwithkey:@"p_id" ascending:yes]; fetchrequest.sortdescriptors = @[descriptor]; nsarray *matches = [context executefetchrequest:fetchrequest error:nil]; nslog(@"matches = %@",[matches valueforkey:@"p_date"]); arrdateobjects = [matches mutablecopy];
in cellforrow this
day *objday = [arrdateobjects objectatindex:indexpath.row-1]; cell.titlelabel.text = day.p_from;
in tableview data showed correctly. problem dat when same thing in didselectrowatindexpath
. null when log day.p_from
.
can me ?
edit numberofsections
(nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. int sections = 0; sections = 1; return sections; }
my numberofrowsinsection
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { int rows = 0; rows = 8; //showing 7 days + 1 row little title return rows; }
my cellforrowatindexpath
static nsstring *simpletableidentifier = @"openingcell"; openingcell *cell = (openingcell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"openingcell" owner:self options:nil]; cell = [nib objectatindex:0]; } if(indexpath.row == 0){ cell.lblday.text = nslocalizedstring(@"lbldag", nil); cell.lblfrom.text = nslocalizedstring(@"lblvan", nil); cell.lbltill.text = nslocalizedstring(@"lbltot", nil); }else{ day *objday = [arrdateobjects objectatindex:indexpath.row-1]; nslog(@"day object in cell = %@",objday.p_from); nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"yyyy-mm-dd"]; nsdate *date = [dateformat datefromstring:objday.p_date]; nsdateformatter *dateformat2 = [[nsdateformatter alloc] init]; [dateformat2 setdateformat:@"dd/mm"]; nsstring *datestring = [dateformat2 stringfromdate:date]; nslog(@"date: %@", datestring); cell.lblshort.text = datestring; cell.lblday.text = [arrdays objectatindex:indexpath.row-1]; nsstring *txtfrom = [objday.p_from substringwithrange:nsmakerange(0, 5)]; cell.lblfrom.text = txtfrom; nsstring *txttill = [objday.p_till substringwithrange:nsmakerange(0, 5)]; cell.lbltill.text = txttill; } return cell;
nslog(@"matches = %@",[matches valueforkey:@"p_date"]); arrdateobjects=[[nsmutablearray alloc]init]; [arrdateobjects addobject:[matches objectatindex:indexpath.row-1]];
instead of
nslog(@"matches = %@",[matches valueforkey:@"p_date"]); arrdateobjects = [matches mutablecopy];
Comments
Post a Comment