Note that there are some explanatory texts on larger screens.

plurals
  1. POCoreData with relationship in the same UItableView
    text
    copied!<p>I need to load the "Main Entity" that has a relationship one-to-many with "Child Entity" into the same UITableView, how can i do? Thanks in advance.</p> <p><strong>Update</strong></p> <p>i use the following code to populate the UITableView:</p> <pre><code> - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [[[fetchedResultsController sections] objectAtIndex:section] name]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ id &lt;NSFetchedResultsSectionInfo&gt; sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; if (self.selectedIndexPath) { return [sectionInfo numberOfObjects] + [self.childArray count]; }else { return [sectionInfo numberOfObjects]; } } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ OreRecupero *selectedObj=(OreRecupero*)[self.fetchedResultsController objectAtIndexPath:indexPath]; OrarioMainCell *cell = nil; if (indexPath == self.selectedIndexPath) { NSUInteger giorniCount = [selectedObj.giorni count]; NSInteger row = indexPath.row; if (indexPath.row &lt; giorniCount) { cell = (OrarioMainCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell=(OrarioMainCell *)[[[NSBundle mainBundle]loadNibNamed:@"myCustomCell" owner:self options:nil]objectAtIndex:11]; radiusLabel=[[LabelRadiusAndText alloc]init]; } UIImageView *bgImage=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"fondoCella"]]autorelease]; cell.backgroundView=bgImage; [df setDateFormat:@"HH:mm"]; cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@",[df stringFromDate:selectedObj.oraInizio],[df stringFromDate:selectedObj.oraFine]]; } else { cell = (OrarioMainCell *)[tableView dequeueReusableCellWithIdentifier:@"DetailCell"]; if (cell == nil) { cell=(OrarioMainCell *)[[[NSBundle mainBundle]loadNibNamed:@"myCustomCell" owner:self options:nil]objectAtIndex:13]; radiusLabel=[[LabelRadiusAndText alloc]init]; } GiornoRecupero *giorno = [childArray objectAtIndex:row]; cell.textLabel.text = [NSString stringWithFormat:@"%i", giorno.oreStraordinario]; cell.detailTextLabel.text = [NSString stringWithFormat:@"%i", giorno.durata]; } } else { cell = (OrarioMainCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell=(OrarioMainCell *)[[[NSBundle mainBundle]loadNibNamed:@"myCustomCell" owner:self options:nil]objectAtIndex:11]; radiusLabel=[[LabelRadiusAndText alloc]init]; } UIImageView *bgImage=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"fondoCella"]]autorelease]; cell.backgroundView=bgImage; [df setDateFormat:@"HH:mm"]; cell.orariLbl.text = [NSString stringWithFormat:@"%@ - %@",[df stringFromDate:selectedObj.oraInizio],[df stringFromDate:selectedObj.oraFine]]; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ OreRecupero *selectedObj=(OreRecupero*)[self.fetchedResultsController objectAtIndexPath:indexPath]; NSIndexPath *dropDownCellIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; //if user tapped the same row twice let's start getting rid of the control cell if (!self.selectedIndexPath) { // Show Drop Down Cell for (GiornoRecupero *giorno in selectedObj.giorni) { [self.childArray addObject:giorno]; } [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:dropDownCellIndexPath] withRowAnimation:UITableViewRowAnimationTop]; self.selectedIndexPath = indexPath; } else { NSIndexPath *currentdropDownCellIndexPath = [NSIndexPath indexPathForRow:self.selectedIndexPath.row + 1 inSection:self.selectedIndexPath.section]; if (indexPath.row == self.selectedIndexPath.row) { // Hide Drop Down Cell [self.childArray removeAllObjects]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:currentdropDownCellIndexPath] withRowAnimation:UITableViewRowAnimationTop]; self.selectedIndexPath = nil; } else if (indexPath.row == currentdropDownCellIndexPath.row) { // Dropdown Cell Selected - No Action return; } else { // Switch Dropdown Cell Location [self.myTableView beginUpdates]; // Hide Dropdown Cell [self.childArray removeAllObjects]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:currentdropDownCellIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; // Show Dropdown Cell NSInteger dropDownCellRow = indexPath.row + ((indexPath.row &gt;= currentdropDownCellIndexPath.row) ? 0 : 1); dropDownCellIndexPath = [NSIndexPath indexPathForRow:dropDownCellRow inSection:indexPath.section]; for (GiornoRecupero *giorno in selectedObj.giorni) { [self.childArray addObject:giorno]; } [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:dropDownCellIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; self.selectedIndexPath = [NSIndexPath indexPathForRow:dropDownCellIndexPath.row - 1 inSection:dropDownCellIndexPath.section]; [self.myTableView endUpdates]; } } } </code></pre> <p>i would like to insert new rows using didSelectRowAtIndexPath method, getting data from "Child Entity"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload