使用 Core Data 数据模型实例化新对象

发布于 2024-10-26 02:27:32 字数 570 浏览 0 评论 0原文

基本上我有这个iPhone应用程序,它从应用程序sqlite数据库(来自实体:模块)获取有关不同模块(学生研究的主题)的数据,并将它们显示在uitableview中..当您单击一个单元格(代表一个module),它推送一个包含模块详细信息的视图控制器。

“模块”属性: name = 模块名称,body = 用户可以为模块保存的注释。

我添加了一个评估实体,其属性为:

“评估”属性: 类型 = 考试或作业,名称 = 作业名称,数据 = 到期日期 Core Data Datamodel

我想要做的是:

  1. 询问用户他们对特定模块有多少评估(例如“如何你对“模块a”有很多评估吗?”
  2. 然后用户会说出一个数字(例如3),然后应用程序应该以某种方式添加例如3,评估并在模块视图中为每个评估显示信息(即文本字段等)页(当用户选择模块时会被推送)

如果有人可以提供帮助,我们将不胜感激。如果我的解释有点令人困惑,我也深表歉意。

basically i have this iphone application that fetches data about different modules (subjects studied by student) from the applications sqlite database (from entity: module) and displays them in a uitableview.. at the moment when you click on a cell (that represents a module), it pushes a viewcontroller that contains details of the module.

'Module' attributes: name = module name, body = notes that user can save for the module.

i have added an assessment entity and its attributes are:

'Assessment' attributes: type = exam or assignment, name = name of assignment, data = date that it is due
Core Data Datamodel

What i want to do is:

  1. Ask the user how many assessments they have for a specific module (e.g. "how many aassessments do you have for 'module a'?"
  2. And then the user would say a number (e.g. 3), then the application should somehow add e.g. 3, assessments and show information (i.e. textfields etc) for each assessment in the module view page (that gets pushed when user selects a module)

If anyone can help, it would be greatly appreciated.. Also apologies if my explanation is a bit confusing..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2024-11-02 02:27:32

首先,您希望将评估与模块之间的逆关系放入其中。

然后您可以创建模块对象,

for(int i=0;i<userInputValue;i++){
    AssessmentObject *anAssessment=     [NSEntityDescription insertNewObjectForEntityForName:@"Assesment" inManagedObjectContext:self.managedObjectContext];
    [anAssessment setDate:[NSDate date]];
    [anAssessment setName:@"Untitled module"];
    [anAssessment setModule:self.currentModule];

} 

一旦分配了它们,您需要将它们推送到模态视图以控制输入,

ModalViewController *aModalViewController=[[ModalViewController alloc] init];
aModalViewController.assessmentSet = [self.currentModule assessments];
[self.navigationController pushModalViewController:aModalViewController animated:YES];

然后您需要设置 modalViewController 以允许编辑一组中的对象。也许是一些下一个/上一个按钮,然后让它在关闭时保存上下文。
实体的外观

first of all you want to put an inverse relationship in from assessment back to module.

then you can create the module objects,

for(int i=0;i<userInputValue;i++){
    AssessmentObject *anAssessment=     [NSEntityDescription insertNewObjectForEntityForName:@"Assesment" inManagedObjectContext:self.managedObjectContext];
    [anAssessment setDate:[NSDate date]];
    [anAssessment setName:@"Untitled module"];
    [anAssessment setModule:self.currentModule];

} 

once they have been allocated then you need to push them to the modal view to control input

ModalViewController *aModalViewController=[[ModalViewController alloc] init];
aModalViewController.assessmentSet = [self.currentModule assessments];
[self.navigationController pushModalViewController:aModalViewController animated:YES];

you would then need to setup the modalViewController to allow editing of the objects in a set. maybe some next/previous buttons, and then get it to save the context when dismissed.
How the entities should look

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文