0

我的 coreDatabase 中有一个实体“Day”。在一个方法中,我从该实体获取数据并将其放入 mutuableArray dayObjects。你可以在这里看到代码。

  NSManagedObjectContext *context = [RKManagedObjectStore defaultStore].persistentStoreManagedObjectContext;
    NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Day"];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:
                              @"p_date >= %@ and 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];

在我的 cellForRow 我这样做

  Day *objDay = [arrDateObjects objectAtIndex:indexPath.row-1];
  Cell.titlelabel.text = day.p_from;

在我的表格视图中,数据显示正确。当我在我的DidSelectRowAtIndexPath. 我总是得到一个空值log day.p_from

有谁能够帮助我 ?

编辑 我的 numberOfSections

 (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    int sections = 0;
     sections = 1;

    return sections;
}

我的 numberOfRowsInSection

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int rows = 0;
    rows = 8; //showing 7 days + 1 row for a little title
    return rows;
}

我的 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 from = %@",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;
4

2 回答 2

0
//try
arrDateObjects = [NSMutableArray arrayWithArray:matches];
//instead of
arrDateObjects = [matches mutableCopy];
于 2013-04-09T09:36:58.803 回答
0
 NSLog(@"matches = %@",[matches valueForKey:@"p_date"]);
    arrDateObjects=[[NSMutableArray alloc]init];
    [arrDateObjects addobject:[matches objectAtindex:indexpath.row-1]];

代替

  NSLog(@"matches = %@",[matches valueForKey:@"p_date"]);
    arrDateObjects = [matches mutableCopy];
于 2013-04-09T10:08:02.677 回答