Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How is it not working? It helps to describe what results you are seeing.</p> <p>You are not adding your sort descriptors to your NSFetchRequest, at least in the sample you provided.</p> <p>Your sort descriptors are ineffective. It appears that <code>Patient</code> is a relationship so sorting against the relationship will not work. You would want to do a sort like the following:</p> <pre><code>NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"patient.lastName" ascending:YES]; NSSortDescriptor *firstNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"patient.firstName" ascending:YES]; NSSortDescriptor *dueDateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"dueDate" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects: lastNameDescriptor, firstNameDescriptor, dueDateDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; [lastNameDescriptor release], lastNameDescriptor = nil; [firstNameDescriptor release], firstNameDescriptor = nil; [dueDateDescriptor release], dueDateDescriptor = nil; </code></pre> <p>You do <strong>not</strong> need to cast <code>[fetchedResultsController objectAtIndexPath:indexPath]</code> as it returns id.</p> <p>What are you getting back from the call to <code>[fetchedResultsController objectAtIndexPath:indexPath]</code>? Put a breakpoint here and check the value and make sure you are getting back a <code>NSManagedObject</code> instead of nil. Putting a breakpoint in that method will also confirm that you are getting called.</p> <p>Your secondKeypathName will not work as mentioned above. You probably want to set it to <code>@"patient.lastName"</code> so that it will match the initial sort I described above. </p> <p>Your <code>-tableView: titleForHeaderInSection:</code> should be accessing the cache provided by the <code>NSFetchedResultsController</code> instead of <em>assuming</em> that there is going to be a row in the section:</p> <pre><code>- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { id sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo name]; } </code></pre> <p>Finally, if you want the section to truly display the "lastname, firstname" format then you will need to create a <strong>non-transient</strong> derived value property on your <code>Patient</code> entity that is the <code>fullName</code> so that you can create your cache based on it. This derived value would then need to be updated any time that the first name or last name were changed.</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