开发者

How To Get Name From NSArray

开发者 https://www.devze.com 2023-03-22 08:20 出处:网络
I have a NSFetchRequest to search of core data entities.It finds them fine, but I want to set the cell\'s text to the entity\'s name attribute.

I have a NSFetchRequest to search of core data entities. It finds them fine, but I want to set the cell's text to the entity's name attribute.

I currently have this but I am setting the object itself to the title, instead of the name attribute, how can I fix this?

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Routine" inManagedObjectContext:self.managedObjectContext];
[f开发者_如何转开发etchRequest setEntity:entity];
NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
self.routineArray = results;
[fetchRequest release];

cell.textLabel.text = [self.routineArray objectAtIndex:indexPath.row];


Try :

cell.textLabel.text = [[self.routineArray objectAtIndex:indexPath.row] name];

EDIT

If your Routine instances are in routineArray (given that name, I suppose) :

// get the Routine instance
Routine *r = [self.routineArray objectAtIndex:indexPath.row];
// now you got your instance, set anything you want on r...
// ...
// and then set its name as the text for textLabel using previous instruction
0

精彩评论

暂无评论...
验证码 换一张
取 消