سؤال

So I want to display some info based on the user selection, and i want this selection to be saved in coreData so in the future a table view only displays the info that the user wants.

Im using MagicalRecord:

+(void)insertNewSeccion:(NSString *)seccion{

[Seccion MR_truncateAll];

[MagicalRecord saveUsingCurrentThreadContextWithBlock:^(NSManagedObjectContext *localContext) {

    Seccion *myseccion = [Seccion MR_createEntity];

    myseccion.seccion = seccion;

    //[[NSManagedObjectContext MR_defaultContext] MR_saveNestedContexts];

} completion:^(BOOL success, NSError *error) {

}];

}

+(NSString *) oneSeccion{

    return [[Seccion MR_findAll] lastObject];

}

And im calling it this way (writing):

     - (IBAction)PrepaAction:(id)sender {

    [CoreDataBase insertNewSeccion:@"prep"];

    [self reloadSeccion];
}

And for reading:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

   if ([[CoreDataBase oneSeccion]isEqualToString:@"prep"]) {
        return _TitlePrep.count;
    }
    return 0;

}

And Im getting this log:

[NSManagedObjectContext(MagicalRecord) MR_contextWithStoreCoordinator:](0x4ac0ac) -> Created Context UNNAMED
2014-02-09 16:07:15.206 CMT[54120:70b] +[NSManagedObjectContext(MagicalRecord) MR_setRootSavingContext:](0x4ac0ac) Set Root Saving Context: <NSManagedObjectContext: 0xc871050>
2014-02-09 16:07:15.207 CMT[54120:70b] +[NSManagedObjectContext(MagicalRecord) MR_newMainQueueContext](0x4ac0ac) Created Main Queue Context: <NSManagedObjectContext: 0xc870f00>
2014-02-09 16:07:15.208 CMT[54120:70b] +[NSManagedObjectContext(MagicalRecord) MR_setDefaultContext:](0x4ac0ac) Set Default Context: <NSManagedObjectContext: 0xc870f00>
2014-02-09 16:07:19.722 CMT[54120:70b] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0xc870f00) → Saving <NSManagedObjectContext (0xc870f00): *** DEFAULT ***> on *** MAIN THREAD ***
2014-02-09 16:07:19.723 CMT[54120:70b] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0xc870f00) → Save Parents? 1
2014-02-09 16:07:19.723 CMT[54120:70b] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0xc870f00) → Save Synchronously? 0
2014-02-09 16:07:19.768 CMT[54120:70b] -[Seccion isEqualToString:]: unrecognized selector sent to instance 0xb43e580
2014-02-09 16:07:19.782 CMT[54120:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Seccion isEqualToString:]: unrecognized selector sent to instance 0xb43e580'

So what is wrong? the problem is when reading because if I comment the tableview it writes but it dont read. I will appreciate your help, thanks.

هل كانت مفيدة؟

المحلول

-[Seccion isEqualToString:]: unrecognized selector sent to instance 0xb43e580

The instance 0xb43e580 is not a string but it is a object is of class Seccion. You should be looking for the attribute called seccion.

Change your numberOfRowsInSection:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   if ([[[CoreDataBase oneSeccion] seccion] isEqualToString:@"prep"]) {
   //  ^^                          ^^^^^^^^          
   return _TitlePrep.count;
   }
   return 0;
}

You might want to consider using a different name for the attribute. Having an attribute called the same as the class can be confusing.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top