如何为 UITableView 创建详细视图以允许我编辑 Core Data 中的数据?

发布于 2024-11-03 07:25:17 字数 512 浏览 0 评论 0原文

我是 iOS、Objective-C 的新手,之前只做过少量的 OO 编程,但很享受尝试创建这个应用程序的挑战。

应用程序摘要: 我有一个视图,它只是将信息输入核心数据数据库的表单,例如。姓名、地址及地址电话。然后另一个视图包含一个表视图,其中列出了当前数据库中的所有人员姓名。

然而,这就是我陷入困境的地方......

我创建了一个详细视图,以便当用户选择表格单元格时,详细视图会加载,但我想将核心数据中的数据返回到他们最初输入数据所用的表单中因此可以对其进行修改/编辑并重新保存回核心数据。

这样做的最佳实践是什么?

我需要将一些数据传递到详细视图,详细视图知道该怎么做,但我应该传递什么?如何告诉详细视图我希望加载 Core Data 数据库中的哪一行数据?

我是否传递 tableview indexPath.row 值?这是否对应于加载详细视图时我可以在 CoreData 中过滤的任何内容?

预先感谢任何回复的人,非常感谢从方法论到在线 tuts

Matt 的任何帮助

I'm new to iOS, Objective-C and have only done a small ammount of OO programming before but enjoying the challenge of trying to create this app.

Summary of app:
I have a view which is just a form to enter information into the Core Data database eg. Name, Address & Telephone. Then another view which contains a Table View which lists all the names of people currently in database.

However this is where i'm stuck...

I have created a detailed view so that when a user selects a Table Cell the detailed view loads but i want to get data from Core Data back into the form they used to originally enter the data so it can be modified/editted and re-saved back to Core Data.

What are the best practicies of doing this?

I will need to pass some data forward to the detailed view, which know how to do, but what should I pass? how do I tell the detailed view which row of data in the Core Data database I wish to load?

Do I pass the tableview indexPath.row value? does this correspond to anything I can filter down in CoreData when loading the detailed view?

Thanks in advance to anyone who replies, would appreciate any help from methodology to online tuts

Matt

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

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

发布评论

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

评论(2

明媚如初 2024-11-10 07:25:17

我想你可以在这里看到苹果示例代码: CoreRecipes 示例代码< /a>

I think you can see Apple sample code here : CoreRecipes sample code

对岸观火 2024-11-10 07:25:17

按照 TheRonin 的建议,从 CoreRecipes 示例代码中挑选一些部分,我执行了以下操作。

在DetailedViewController上创建Core-Data DataModel对象的iVar

DataStore *enquiry;

在didSelectRowAtIndex下的tableview视图上设置Core-Data DataModel对象和详细视图控制器,

DataStore *enquiry = (DataStore *)[_fetchedResultsController objectAtIndexPath:indexPath];

ShowEnquiryDetail *detailViewController = [[ShowEnquiryDetail alloc] initWithNibName:@"ShowEnquiryDetail" bundle:nil ];

在DetailedViewController中设置Data Model对象

detailViewController.enquiry = enquiry;

,然后将DetailedViewController推送到导航堆栈。

[self.navigationController pushViewController:detailViewController animated:YES];

然后在DetailedViewController上,您可以使用enquiry.name、enquiry.email等从Core-Data中选定的行访问DataModel对象中的数据...

这不是一个写得很好的答案,可能使用了不正确的术语但希望它能帮助那些和我处境相同的人。

Picking out bits from CoreRecipes sample code as suggested by TheRonin I did the following.

Create an iVar of Core-Data DataModel object on the DetailedViewController

DataStore *enquiry;

On the tableview view under didSelectRowAtIndex setup Core-Data DataModel object and Detailed view controller,

DataStore *enquiry = (DataStore *)[_fetchedResultsController objectAtIndexPath:indexPath];

ShowEnquiryDetail *detailViewController = [[ShowEnquiryDetail alloc] initWithNibName:@"ShowEnquiryDetail" bundle:nil ];

set the Data Model object in DetailedViewController

detailViewController.enquiry = enquiry;

then push the DetailedViewController on to navigation stack.

[self.navigationController pushViewController:detailViewController animated:YES];

Then on the DetailedViewController you can access the data in the DataModel object from the selected row in Core-Data using enquiry.name, enquiry.email, etc...

This isn't a well written answer and may use incorrect terminology but hopefully it will help someone in the same position I was.

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