Question

I have a problem with my FCR. I want to show my datas on Labels but FCR doesnt allow me.There is my codes..

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"faturaAdi == 'ADSL' "];

I have fetched only 1 data which fatura name is ADSL.. and I want to write this faturaAdi on my label but i couldn't do that.

NSArray *array = [[NSArray alloc]init];

array = self.fetchedResultsController.fetchedObjects;

_lblFaturaAdi.text = [self.fetchedResultsController.fetchedObjects valueForKey:@"faturaAdi"];

NSLog(@"%@",[array valueForKey:@"faturaAdi"]);

NSLog shows Takip[967:60b] ( ADSL )

When i put the

_lblFaturaAdi.text = [self.fetchedResultsController.fetchedObjects valueForKey:@"faturaAdi"];

app crash with this error ;

-[__NSArrayI length]: unrecognized selector sent to instance 0xa18c740

how can i solve this ?

Was it helpful?

Solution

Your code should change to:

NSArray *array = self.fetchedResultsController.fetchedObjects;

if (array.count > 0) {
    self.lblFaturaAdi.text = [[array objectAtIndex:0] valueForKey:@"faturaAdi"];

    NSLog(@"%@", _lblFaturaAdi.text);
} else {
    NSLog(@"no results found");
}

Because you don't need to initialise an array before replacing it and you need to index into the array before you can extract the value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top