简体   繁体   English

在Xcode 4.2中以编程方式为iPhone应用程序编写UITableView

[英]Programmatically Code a UITableView for iPhone Application in Xcode 4.2

I have been working in Storyboards for a while now and they are perfect for smaller apps. 我已经在Storyboard中工作了一段时间,它们非常适合较小的应用程序。 But I'm trying to put together a collection of 40+ recipes so it's unrealistic for me to drag 40 different Detail Views onto the Storyboard! 但是我正试图汇集40多种食谱,因此将40个不同的“详细视图”拖到情节提要上对我来说是不现实的!

I'm wondering how can I programmatically build a table view with 40 different rows that each lead to the same Detail View, but pull different content? 我想知道如何以编程方式构建包含40条不同行的表视图,每条行均导致相同的详细信息视图,但提取不同的内容? Thinking of storing the content in an array and based on which table cell the user clicks we pull from a different index in the array. 考虑将内容存储在数组中,并根据用户单击的表单元格,我们从数组中的另一个索引中拉出。 So for example if the user clicks on recipe #2 in the table it will load a generic Detail View which populates its data from my array index #2.. Please ask for clarification if I'm not making any sense. 因此,例如,如果用户单击表中的配方#2,它将加载一个通用的详细视图,该视图从我的数组索引2中填充其数据。.请澄清一下我是否没有任何道理。

I've looked through the Apple docs and a lot of their tutorials reference Core Data which I would like to not use... I don't think it's required for iOS 5 and there must be an easier way than using Storyboard to drag-and-drop 40 different Detail Scenes. 我浏览了Apple文档,并且他们的许多教程都引用了我不想使用的Core Data ...我认为iOS 5不需要使用它,而且必须有比使用Storyboard拖动更简单的方法,拖放40个不同的细节场景。

Your question is at a very high level so I can't provide much help other than to provide guidance. 您的问题很高,因此除了提供指导外,我无法提供太多帮助。 Your idea in the second paragraph sounds exactly how you should write your application in iOS. 在第二段中,您的想法听起来完全应该如何在iOS中编写应用程序。

  1. You build a model containing your recipes (CoreData or other store) 您建立一个包含配方(CoreData或其他商店)的模型
  2. Link this to a navigation controller hosting a table view controller (NSFetchedResults controller or your own code or a combination of both) 将此链接链接到承载表视图控制器的导航控制器(NSFetchedResults控制器或您自己的代码或两者的组合)
  3. A selection in the table view pushes the (generic) detail view controller onto the Navigation stack (using the push segue is probably easiest) 表格视图中的选择将(通用)详细信息视图控制器推入导航堆栈(使用推推功能可能最简单)
  4. The detail view controller populates itself (with the detailed recipe instructions) using a unique name that you pass to it that will enable it to load the detailed recipe from your data store 详细信息视图控制器使用传递给它的唯一名称填充自身(带有详细的配方说明),这将使其能够从数据存储中加载详细配方

In fact, I believe that Apple demoed an example app that did exactly this during either WWDC 2010 or WWDC 2011. 实际上,我相信Apple演示了一个示例应用程序,该示例应用程序在WWDC 2010或WWDC 2011期间都做到了这一点。

If there's any section you are not clear on, post a new question detailing what the problem is, what you've tried so far and/or what your errors are. 如果您不清楚任何部分,请发布一个新问题,详细说明问题是什么,到目前为止您尝试过什么和/或错误是什么。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM