I am new to iphone development. I have to develop an iphone application which is basically a questionare. When user runs the application he has to answer around 30 questions, each one at a time. I am planning to use the Navigation template project for this application. Where i can create a view with question and optional answers (in table view) and when user selects an answer, i can push new instance of same view to navigational controller.
Is the the best practice for creating a questionare application. Or a better template exists? Is it advisable to store 30 instances of a view in view controller stack?
regards
sandy
The navigation template is fine. However, I would do it in a slightly different way, mimicking a wizard.
Your initial root view controller should present the first question, when the user selects it, you push on the stack a new view controller in charge of handling the answer. When the user answer the question, you pop the view controller notifying your root view controller. You may do this using a protocol and a delegate or using a notification. Upon receiving the notification, or when the delegate method is called, the root view controller prepares the next question.
Repeat this cycle until the user answer the last question, then your root view controller presents to the user the final result.
Related
I want to create an application.
The application will let people to read jokes, for example. Then people can press a button and another view show up where people can insert their own jokes.
After people finish inserting their own joke, I want them to go back the previous screen.
What would be the standard way to do so?
Put all controllers on application delegate and change the rootviewcontroller?
One possibility would be to use the presentModalViewController:animated: method of the root UIViewController to present the "joke inserter" view.
Once the joke insert was complete (or if the user cancelled the insertion) you'd simply return to the previous view as-is.
The uinavigation controller will work well. U can push people to a new controller where they enter their joke and then pop them back to the root. U can do this with or without animation. Set up the UiNavigationController in the app delegate and initialize it with your jokesviewcontroller as the root.
Here is a post I just did on this subject
Programming iOS: clarifications about Root View Controller
I am trying to write my first iPad app, and I have a problem.
I have my Main view controller with a button. Once the button is pressed, it requests a list of information from a web server, and returns the data. This data, I want to put into a table view in a popover.
I have the main view controller, and the data is received back and put into a dictionary, then that is looped through to get a couple of arrays of data.
I also have a Popover view controller that can display a static table view.
My question is, how do I get the data (either the dictionary, or the arrays) from the Main view controller to the Popover view controller?
I am really lost.
Thanks
James
There are two design patterns you have to keep in mind: delegation and notification. in a more general way also KVO is useful to update your view if the model changed. Of course the object listening for notifications or acting as a delegate is the controller of that view, NEVER the view itself.
There are two things you want to avoid at any time: storing stuff in global variables or in singletons and making "super objects" that act as let us say the model and the controller. Stick to the MVC paradigm and try to loose couple your objects and think about which object owns which other object. This is important for memory management and if you not implement it correctly it will come back to you later.
Check out session #116 - Model-View-Controller for iPhone OS from WWDC10 session videos and session #123 - iPhone View Controller Techniques from WWDC09.
The WWDC10 videos are available for free at apple's developer site.
Hey James, I suggest you first do your homework and try to get a taste on how so-called delegate structure works in most iOS apps.
To be more clear, your main view controller would become the delegate and your popover view controller would become the child of such a delegate. The delegate is responsible for presenting its child controller. At the same time, the child controller is responsible for asking for data from and reporting any changes to its delegate controller.
So in this way your popover controller can get the data it wants from your main view controller, and at the same time, when the user wants to dismiss the popover view, the popover view controller detects the user's instructions and informs the main view controller to dismiss it.
have described another possibility a few seconds ago:
Passing array between view controllers?
I'm diving into iOS development and am getting familiar with navigation view controllers. I'm trying to build a simple app with a table view that allows me to add objects to it. So far, I have a table view with an add "+" button in the nav bar that allows me to load my CreateObjectView and display it modally so the user can define the new object, but when they click the save button, I don't know how to send that object data back to the parent view that created the CreateObjectView that contains the object data.
When I create the child view (CreateObjectView), I could pass into it a pointer to the current view before I push it onto the nav stack, but this just feels dirty and circular.
I was reading about protocols and delegates and I could use that approach as well, but it also feels circular.
This question seems like it would be a common design issue to any tableview-based or nav-based app, how should I probably access the view that is one level up from my current view in a nav-based iOS app?
Thanks so much in advance for all your help!
It feels circular at first, but it is the right way. Before the UINavigationController pushes the new view controller you should set the delegate to the current view controller - assuming that's the object you wish to communicate with. Of course you could set it somewhere else instead, such as to a central Core Data handler. Then when you need to communicate call the delegate with the method you have defined. I've done several navigation apps like this after seeing Apple's cookbook example, and it really works well.
I'm developing an iPhone application and I'm trying to do this:
I want an application with tree views. The view shown first, doesn't have a navigation bar. If the user tap on a button, I need to open the second view with a navigation bar and a table view. The user can also add new items to the table view. If the user do so, the application will show the third view where the user can add fields (this view has also a navigation bar).
It may seem simple, but for me it is not. I don't know how to use the UINavigationController and have not found yet a similar example for what I do (paragraph translated by google).
UPDATE
I don't know how where to put UINavigationController.
How can I do that? Can I use a UIViewController to call a UINavigationController?
Thank you.
take a look at the Recipes example (it also uses core data which may confuse things a little) http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008913
There is also a simpler starting point here http://developer.apple.com/iphone/library/samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318 but the Recipe example covers just about everything you need.
EDIT:added the following
For the very simplest example use XCode to build a new application - a navigation based application (sorry, I'm in front of a PC today so that is from memory). That will give you a blank application with the navigation controller created. You then use the navigation controller to push and pop your view controllers
ViewController Programming Guide
I would like to learn the best practices in reloading the application state, such that when my app is started, it should automatically load the "correct" view/subview when it is opened again.
In my particular case, my app has a bunch of view controllers, each taking care of a UITableView. I would like for my app to "jump" to the correct node within my table view hierarchy when it is opened again.
Building on what Marc said, assuming you've got a base view controller, and then one or more levels of 'drill-down', load all your view controllers up to the 'current' one using [navigationController pushViewController: viewController animated: NO]. Then, when the user hits the Back button, they'll be presented with the pre-loaded previous view controller. A good example of this is the "Contacts" app, which preloads the Groups view controller, then pushes a view controller for the current group (usually "All Contacts") on top of that.
Check Apple's DrillDownSave sample app:
"Demonstrates how to restore the user's
current location in a drill-down list
style user interface and restore that
location when the app is relaunched."
http://developer.apple.com/iphone/library/samplecode/DrillDownSave
You'll need to associate an identifier with each view controller, and save that value to the user defaults when the current view changes. The next time you launch, read that value and you'll know which view controller you need to load initially.
I've published a little library to help doing these kinds of things. I'm already using it in an app I've published on the App Store and it's a lot smoother than implementing NSCoder for every view manually :P