简体   繁体   中英

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. 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!

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? 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.

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.

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.

  1. You build a model containing your recipes (CoreData or other store)
  2. Link this to a navigation controller hosting a table view controller (NSFetchedResults controller or your own code or a combination of both)
  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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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