Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay NSSet data from Core Data
    primarykey
    data
    text
    <p>I am adding values into 2 entities within my core data model and the problem I am facing is trying to properly retrieve the NSSet and target the associated strings when accessing the detail view.I would simply like to display the results in a uitableview. I believe the values are being correctly added along with the relationships to the entities as I previously got help off the forum for it as viewable <a href="https://stackoverflow.com/questions/17557288/how-to-check-if-a-relationship-has-been-established-core-data">here</a>. I am trying to recall the associated <strong>RoutinesDetail</strong> data on the detail view.</p> <p><img src="https://i.stack.imgur.com/1JoDA.png" alt="enter image description here"></p> <p>I know the seague is working correctly as I am able to set the title based on the selectedRow, so it is passing the data between view controllers. I can recall 'Routines' data using <code>Ex.routinename</code></p> <p>Using the following to debug and try to allocate the NSSet as I read a way to display it was to use <code>allObjects</code> but this didn't work: </p> <pre><code>NSArray *test= [Ex.routinedet allObjects]; NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:@"image" ascending:YES]; test = [test sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]]; NSLog(@"Image *** %@",test); </code></pre> <p>This produces the following report which makes me question whether I am doing it right?</p> <blockquote> <p>"&lt;RoutinesDetails: 0x7453d80&gt; (entity: RoutinesDetails; id: 0x74531f0 &lt;x-coredata://C075DDEC-169D-46EC-A4B7-972A04FCED70/RoutinesDetails/p1&gt; ; data: &lt;fault&gt;)" )</p> </blockquote> <p>So basically I am looking at how to retrieve <strong>RoutinesDetails</strong>. Any suggestions would be greatly appreciated.</p> <p>**</p> <h2>In case it is needed here is the associated code</h2> <p>**</p> <p><strong>routines.h</strong> - NSManagedObject</p> <pre><code>@class RoutinesDetails; @interface Routines : NSManagedObject @property (nonatomic, retain) id routinename; @property (nonatomic, retain) NSSet *routinedet; @end @interface Routines (CoreDataGeneratedAccessors) - (void)addRoutinedetObject:(RoutinesDetails *)value; - (void)removeRoutinedetObject:(RoutinesDetails *)value; - (void)addRoutinedet:(NSSet *)values; - (void)removeRoutinedet:(NSSet *)values; @end </code></pre> <p><strong>RoutinesDetails.h</strong> - NSManagedObject</p> <pre><code>@class Routines; @interface RoutinesDetails : NSManagedObject @property (nonatomic, retain) NSString * image; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) Routines *routineinfo; @end </code></pre> <p><strong>FBCDRoutineDetailViewController</strong>(sorry if its too much code)</p> <pre><code>#import "FBCDRoutineDetailViewController.h" #import "FBCDRoutineViewController.h" #import "Routines.h" #import "RoutinesDetails.h" @interface FBCDRoutineDetailViewController () @end @implementation FBCDRoutineDetailViewController @synthesize managedObjectContext; @synthesize fetchedResultsController = _fetchedResultsController; @synthesize Ex; - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != nil) { return _fetchedResultsController; } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"RoutinesDetails" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]]; [fetchRequest setFetchBatchSize:20]; NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName: nil]; self.fetchedResultsController = theFetchedResultsController; _fetchedResultsController.delegate = self; return _fetchedResultsController; } - (void)viewDidLoad { [[self navigationController] setNavigationBarHidden:NO animated:YES]; [super viewDidLoad]; // Do any additional setup after loading the view. NSArray *test= [Ex.routinedet allObjects]; NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:@"image" ascending:YES]; test = [test sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]]; NSLog(@"Image *** %@",test); self.title = Ex.routinename; NSLog(@"Image *** %@",Ex.routinename); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view delegate - (IBAction)save:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } - (IBAction)cancel:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo numberOfObjects]; } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { //RoutinesDetails *info = [_fetchedResultsController objectAtIndexPath:indexPath]; NSArray *test= [Ex.routinedet allObjects]; NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:@"image" ascending:YES]; test = [test sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]]; //cell.textLabel.text = info.image; cell.textLabel.text = [[test objectAtIndex:indexPath.row] name]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"routineCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Set up the cell... [self configureCell:cell atIndexPath:indexPath]; return cell; } </code></pre> <p>Any suggestions would be greatly appreciated.</p>
    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