0

我创建了一个新项目,其中默认情况下已经使用添加日期的添加按钮完成了表格视图。但是该项目对 nsmanagedobject 的事情并不熟悉。我想在这个不是日期中添加特定的字符串。谢谢帮助!!

NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];
4

2 回答 2

1

It sounds like you need to learn about Core Data. I would also recommend Core Data: Apple's API for Persisting Data on Mac OS X by Marcus S. Zarra.

To display a string, rather than a date, you need to modify the data model. The template created a data model with a sigle Event entity that has a data attribute.

You can remove or rename this entity and modify the attributes as desired. You want to add a string attribute.

Then, you will want to specify the name of your new string attribute as the key for sorting in the fetch. You will also want to use it to set the value of the text in the table view cell's text label. Finally, you will need to modify the insert new object method to set a default value for the new attribute.

于 2010-02-13T19:19:46.343 回答
0

Looks like you've started a project using Core-Data. If you don't know what Core-Data is or how to use it, you can find out more here:

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/CoreData.pdf

于 2010-02-13T19:12:14.360 回答