jwknz
jwknz

Reputation: 6824

ios - show core data results in a UILabel?

I know how to set a UILabel and populate it with a NSString, so am I wrong to assume that I can load a attribute of a Core Data database into an NSString and show that result into an UILabel?

If I am right that this is possible, how do I go about that? I have bits a pieces of code I trying to piece together as I am learning how to do this:-)

I want to show this result in a normal UIView rather than a UITableView.

Cheers Jeff

Upvotes: 2

Views: 739

Answers (1)

melsam
melsam

Reputation: 4977

You should have NSManagedObject classes to access your Core Data entities. For example, if you have an entity named Person, there should be a corresponding Person class (declared in Person.h and Person.m). For each attribute of that Person class, you should have a corresponding @property. After you've queried your data (usually using an NSFetchRequest), you can then access these properties and assign them to whatever UI control you wish to.

For example:

myLabel1.text = person.firstName;
myLabel2.text = person.lastName;

(assuming firstName and lastName are NSStrings).

Upvotes: 1

Related Questions