开发者

Returning two property values concatenated as one item

I'm not sure if this can be done. I'm just learning how NSFetchedResultsController and Predicates work.

I have a person entity, where two properties are first name and last name. I want them to appear concatenated together in one cell, either as " " or ", , depending on the user'开发者_如何学运维s preference.

In order to use the NSFetchedResultsController for managing my UITableView cells, is there a way to write the fetch request so that the two fields are handled as a combination within the NSFetchedResultsController?


Don't think of Core Data as SQL. The values are not in fields, they are attributes of objects. The fetched results controller returns an array of objects, each of which (presumably) has a firstName and lastName attribute.

To make the concatenated values appear in the UI, you would simply create a concatenated string in the UITableviewDataSource object that provides the tableviews data. Usually, these days you do it in method called something like 'cellForRow:`.

NSManagedObject *mo=[[fetcheResultsController fetchObjects] objectAtIndex:index.row];
NSString *fullName=[NSString stringWithFormat:@"%@ %@",[mo valueForKey:@"firstName"],[mo valueForKey:@"lastName"]];
cell.nameLabel.text=fullName;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜