Note that there are some explanatory texts on larger screens.

plurals
  1. POWorking with NSFetched result controller and sections
    primarykey
    data
    text
    <p>I am new to core data and NSFetched resultcontroller. So far I managed to fill up my tableView. But now I want to divided into sections. Here is how my code looks like.</p> <pre><code>- (void)getKeepers // attaches an NSFetchRequest to this UITableViewController { NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Team"]; request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"sortOrder" ascending:YES]]; self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.genkDatabase.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; } </code></pre> <p>Let me sketch the situation. I am making an app for a football club. In my tableview I want for every position (goalkeeper,defender,winger,attacker) a new section. My core database looks like this.</p> <pre><code>- TEAM -name -Position -img_url -birthDate -sortOrder </code></pre> <p>I added the attribute sortOrder to sort my players. But can anybody help me to divide it into sections?</p> <p>Thanks in advance !!</p> <p><strong>WHAT I DO IN MY CELL_FOR_ROW_AT_INDEX</strong> In my cellForRowAtIndex I am doing not the usual thing. I am working with a custom tableviewCell which contains 6 imageviews. But its possible that a row only contains 4 images. You can see what I am trying to do over <a href="http://www.flickr.com/photos/74322780@N08/8050170687/" rel="nofollow">here</a>.</p> <pre><code>#define IMAGES_PER_ROW 6 NSInteger frcRow = indexPath.row * IMAGES_PER_ROW; // row in fetched results controller for (int col = 1; col &lt;= IMAGES_PER_ROW; col++) { NSIndexPath *path = [NSIndexPath indexPathForRow:frcRow inSection:0]; Team *team = [self.fetchedResultsController objectAtIndexPath:path]; NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:team.image]]; UIImage *image; if (imgData == nil) { // default image image = [UIImage imageWithContentsOfFile:@"keeperNil.jpg"]; } else { image = [UIImage imageWithData:imgData]; } [cell setImage:image forPosition:col]; frcRow ++; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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