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.
You build a model containing your recipes (CoreData or other store)
Link this to a navigation controller hosting a table view controller (NSFetchedResults controller or your own code or a combination of both)
A selection in the table view pushes the (generic) detail view controller onto the Navigation stack (using the push segue is probably easiest)
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.
Related
Hello fellow StackOverflowers, I am in a bit of a dilemma with trying to condense the code in my application, iEngineering, that is available for free on the AppStore. Please download it so you can follow along with the rest of this post.
Alright, so when creating the current version of iEngineering, I used a new UIViewController with a UITableView for every "new" screen for all of the listing (table view) screens. The one story board file I am using currently has ~100 view controllers, takes 10 minutes to load, and several minutes to load the simulator. Big, big rookie mistake.
I am currently in progress in developing a plan to condense all of the UITableViewControllers into a single reusuable UITableViewController if it's feasible. However, I am running into trouble in figuring out what topics I should research to learn out how to refresh/present an updated listing (table view) in the view controller if you segue/transition to a subdirectory screen of the app. For example, selecting "Chemical Engineering" in the home screen and transitioning to the next listing screen that displays the following: "General Chemistry, Fluid Mechanics, Reactor Design, Separations, and Thermodynamics."
Would this be a reasonable/feasible task to condense down my current project? If so, what topics should I research to figure out how to do the transitioning/updating to a new table view screen?
In the images below, I am trying to condense the view controllers into only a couple of view controllers (Note: The image doesnt display the 80+ view controllers off the screen. xCode wouldn't zoom out anymore.)
I need to create an ipad app for restaurant so it acts like a menu,
To the left is a list of food and to the right is a column
So when customer order something, say food A,
A tab will be added to the right column, displaying food A on it
Just like that in iPhone's clock app - Alarm section
Customer can delete unwanted order later in the column
I'm new to xcode, so I imagine what I'm suppose to use is UITableView
Can anyone give me some example on how to create those tabs?
Thank you very much in advance
Check out the Tabster iphone app sample code. That should help you get over the hump.
You need to use UITabBarController with array of UINavigationControllers depending on the complexity of your usecasse.
For the rows and sections, use UITableViewController. Just check any sample code of Apple on UITableViewController. They have plenty. Both simple and complex. Example: TableViewSuite
I think this could work as two UITableViewControllers, side by side. One side is the list of what can be ordered, the other side is list of what has been selected. The first side is not editable, the second side is editable (to delete items no longer wanted).
Using UINavigationController is optional - it could certainly be done on 1 view without any pushing/popping of viewControllers.
Along with the examples listed by mbh you might also watch the Stanford iOS class on iTunes U, specifically lecture 9 (Table Views).
If you need to save this data for later reference you'll also want to check out lectures 13 and 14 on Core Data - there is a very useful class called CoreDataTableViewController available - it could save you a couple days. http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/289
Good luck,
Damien
How hard is it to create a UI, which views is based on the data that a user has?
So say I can have a scroll view, and a particular user A can have a view which consists of X,Y,Z and user B can have a view which consists or Y, Z? I am just concerned about positioning the views in a views because we can't do that now via interface builder and it needs to be coded.
You can build an entire app with multiple views and controls without touching Interface Builder. The UI views and elements can all be allocated and configured programmatically.
Apple even has a WWDC 2010 video on how to build data driven app UIs.
In case anyone else is looking for Data Driven UI information the WWDC post from WWDC2010 is at about 40-41minutes in the Game development video part 1 (Video 401).
Other than that there is not a lot of information on data driven UI for Objective-C. I am about to add it to an existing project because we need multiple layouts for the same screen and i found it hard to just switch the view based on the layout (wrecked the bindings from memory).
Shouldn't be too hard though, simple framework to load the plist and use KVC to set all the values.
If people are new to KVC i would recommend adding the following method to stop errors happening when you set keys that don't exist, esp. if non-programmers are going to do some of the layout.
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
NSLog(#"The key %# does not exist.", key);
}
You can either do a callback-based approach like UITableView, i.e. -cellForRowAtIndexPath, or a more explicit setter like UIMenu where you set the items.
For the latter approach, have a -setObjectsArray: or similar method where you configure your subviews according to the input data, i.e., make sure you have three of them if you have (x,y,z) and set their data to 0th view = x, 1st view = y, etc.
Next override -layoutSubviews and set the frames of each of the views based on their position in the order and your bounds.
Does that help?
FYI: It's session # 117: "Building a Server-Driven User Experience"
You can find it through iTunesU:
Search for WWDC2010
Go to "Application Frameworks"
Get "Session 117 - Building a Server-Driven User Experience"
The link to the PDF slides is on the page: WWDC 2010 Session Videos
Ray
I am primarily a web developer (ruby, python) that is new to iPhone development. I've done some desktop development in the past within the MS environment (C#), but never anything on the mac.
I'm trying to build a really simple iPhone application and I am confused by the way that views work in general. If someone can provide advice for my particular problem, along with some resources where I can learn how to architect iPhone views in the future, that would be awesome. I feel like a lot of the Apple documentation that I've come across is too specific - I am lacking a fundamental understanding of how views work on the iPhone.
My particular problem looks like this:
I need one view that displays some downloaded text content. This is the view that shows when the app loads, and it is pretty straightforward.
Then I need a settings area (I've already decided I don't want to use the iPhone settings area). The settings area main page will have some text fields on it. It will also have a 2-row grouped table. Each cell in that table will take you to another view which also has a grouped table used for multi-select. I suspect that I can reuse the same view for these two final "detailed setting" views.
In summary:
home page
settings main page
detailed setting 1
detailed setting 2
Any help and advice appreciated.
It sounds like you already have a good idea of what you want each of your screens to look like; that's a good place to start.
What you're probably going to want to do is use Interface Builder to lay out the objects in each view (textfields, buttons, etc.), and then have a custom View Controller (subclass of UIViewController) for each view. You would then navigate to a new view by doing something like:
MySettingsController *controller = [[MySettingsController alloc]
initWithNibName:#"SettingsView" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
(assuming a navigation-based app).
If you haven't yet, I recommend reading Apple's View Controller Programming Guide
Some advice: Despite your back ground, don't think of the views as pages or the app as a web site. That will cause you problem in your design because the technology is different and views don't work like web pages and apps don't work like web sites.
The major difference is that while web pages often contain actual data, views do not. The view object is only concerned with display. It doesn't know what it is displaying and it doesn't store or logically manipulate the data. The data comes into the view from the view controller which itself gets it from the data model.
See Cocoa Core Competencies: Modal View Controller
Rails uses MVC if you've used that with Ruby. The basic principles are the same.
Well, there are plenty of information on Apple developers' pages: you could start reading Your first iPhone application
There are quite a few good sites with very good info both on cocoa and iPhone developing:
Cocoa with love
iCode blog
and many more (google is your friend in this).
A couple of books I liked are "Beginning iPhone3 Development" and "iPhone developer cookbook".
The first is probably more useful at the beginning (no pun intended)
As for the specific case of yuor application, you could use a navigation controller for the settings page, and each time you need to dive into the details you will just push the right view onto the navigation controller's view stack.
So you would design 4 views with the interface builder
Main view
Settings view
Detail 1
Detail 2
And then push the views onto the navigation controller.
It's pretty straightforward, I won't go into the details, but just searching something like "iphone navigation controller example" on google will give you plenty of samples that you can easily adapt to your needs.
These were all helpful responses, in particular the reference to the iPhone View Programming Guide. This helped me to diagnose my misunderstanding which was related to the role of View Controllers, and the relationship between individual views and view controllers. I think part of my confusion came from learning MVC in the context of Rails, where this relationship is quite different.
For others looking for advice in this general area, I would recommend checking out Lecture 6 from Stanford's iTunes U iPhone Application Development course from Winter 2010 "Designing iPhone Applications, Model-View-Controller, View Controllers", and the lectures 5 & 7 if you have time. I think that was when the penny dropped for me, despite having already looked at a few of the books mentioned here.
i am a student and also new to iphone SDK.i want to do xml parsing which has image URL and Data,it is a XML file about news.i have to show it .can i use table view or navigation controller? which is the best way?i have to show images and titles in first page.when i click it,it shows other page to show full news with image. is there any tutorial for what i need?
Table View and Navigation controllers are two entirely different things. It's like asking whether you should use a hammer or a nail to hang something. You could use both. YOu could also use a screw and a screwdriver, or any number of other ways to hang something on the wall.
A Navigation controller allows you to move around in a view heirarchy. See the Apple Contacts app to see how you can move around. Now, if you want to have a list of items, then you could use TableView to make a table of items. You don't have to have a UITableView inside a Navigation controller view. Or you may want to.
I would start at Apple's Creating iPhone Apps, and then go look at the Stanford's online course, and this one, among countless others.
You have chosen to bite off quite a big chunk with your first project.