如何为 UITableView 创建详细视图以允许我编辑 Core Data 中的数据?
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你可以在这里看到苹果示例代码: CoreRecipes 示例代码< /a>
I think you can see Apple sample code here : CoreRecipes sample code
按照 TheRonin 的建议,从 CoreRecipes 示例代码中挑选一些部分,我执行了以下操作。
在DetailedViewController上创建Core-Data DataModel对象的iVar
在didSelectRowAtIndex下的tableview视图上设置Core-Data DataModel对象和详细视图控制器,
在DetailedViewController中设置Data Model对象
,然后将DetailedViewController推送到导航堆栈。
然后在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
On the tableview view under didSelectRowAtIndex setup Core-Data DataModel object and Detailed view controller,
set the Data Model object in DetailedViewController
then push the DetailedViewController on to navigation stack.
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.