Note that there are some explanatory texts on larger screens.

plurals
  1. PONSArrayController initialization
    primarykey
    data
    text
    <p>I am having trouble getting an core-data backed NSArrayController to work properly in my code. Below is my code:</p> <pre><code>pageArrayController = [[NSArrayController alloc] initWithContent:nil]; [pageArrayController setManagedObjectContext:[self managedObjectContext]]; [pageArrayController setEntityName:@"Page"]; [pageArrayController setAvoidsEmptySelection:YES]; [pageArrayController setPreservesSelection:YES]; [pageArrayController setSelectsInsertedObjects:YES]; [pageArrayController setClearsFilterPredicateOnInsertion:YES]; [pageArrayController setEditable:YES]; [pageArrayController setAutomaticallyPreparesContent:YES]; [pageArrayController setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES]]]; BOOL result = [pageArrayController setSelectionIndex:0]; </code></pre> <p>When I attempt to call setSelectionIndex:, it returns YES, indicating that the selection has been successfully changed. However, any subsequent getSelectionIndex calls to the pageArrayController object returns NSNotFound.</p> <p>What I don't understand is that if I put the NSArrayController into a NIB, and allow the NIB file to perform the initialization (with all of the same attributes in Interface Builder), the NSArrayController works correctly.</p> <p>Why is there a difference in behavior? Does the NIB file initialize these types of objects in a special way? Is my initialization of the NSArrayController incorrect?</p> <p>Any help is appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    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