Should we Ever Change RootView Controller of IPhone Application? - iphone

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

Related

Force return to a given view when going to backkground

My application has an initial view asking a password and, when the password is valid, going to a view controller thru a segue.
When application is moving to the background, I would like to force a return to the initial view .
I guess that the corresponding code has to be inserted into app delagate applicationWillResignActive method but after a ton of attempts I can't find the appropriate code.
Thanks in advance for any help.
You need to make sure your controllers are embedded in a navigation controller, and then simply use
popToRootViewControllerAnimated:
if the target controller is the first one, or
popToViewController:animated:
if the target view controller is not the first one. Both methods are called on self.navigationController.

Segue to Tab Bar Controller with performSegueWithIdentifier

I'm learning iOS and I'm working on what amounts to a Proof of Concept app in XCode 4.2. I essentially want to allow a user to enter a user/pass combo and if the user is in an array of objects, pass them on to the "Content" view, but if not, pass them on to the "Register" view.
In either case, since the app itself will be a tabbed app (though the login and register views are not tabbed), I need to be able to segue from a typical ViewController to a TabViewController.
- (void)logIn:(id)sender{
[self performSegueWithIdentifier:#"Content" sender:sender];
}
Currently, I have the app segueing to the proper ViewController, which is a TabBarController embedded in a NavViewController...but once it gets there...there are no tabs!!
What am I doing wrong?
Now you aren't loading TabBarController that's why you don't have any tabs.
What I suggest you:
In Log In ViewController you can also add "register" button, and place a segue from it to Register View Controller.
Add IBAction from log in button, which will check for log in and pass, and if it's OK load Content ViewController or TabBar Controller with Content ViewController.
I strongly recommend you to study iOS5 storyboard tutorials to get to know how the view controllers interacts.

How to design multiple views in iPhone

I am making code for iPhone. My first screen has only one button with text Menu. When user will click on this button next screen is coming with multiple navigation bar.Each Navigation bar has their own Text information which are being selected after clicking on any Navigation bar.
How i should to design it for iPhone ? Please give me concept. Should i take multiple views ? If i have multiple views how will i hide and show on button click event ?
Thanks in advance.
You will have to adapt your user interface to comply to how Apple wants an app to work, look, and feel - or make your own custom viewcontrollers. Even then, you might not get the exact behavior you want.
My hottest tip is to look at similar apps on appstore and see how they are navigated.
I don't get a picture in my mind from your description, but it seems you want what is called "drill down". This is best done with tableViews.
You can't have multiple navigation controllers on the same "screen"; it doesn't work like that on the iPhone. Instead, what you have is one single Navigation controller, that controls the pushing of views. You decide which sub-view to push depending on which selection the user makes, and the Navigation controller handles the rest of the interaction with the user to let him or her navigate between the views.
Example structure:
Window-based app
+-MainWindow.xib
| +-First view with button
| +-UINavigationController
+-tableview1.xib
+-tableview2.xib
+-any more views you need.
Make the app delegate a <UINavigationControllerDelegate> and declare navCt *UINavigationController, and connect it in Interface Builder. You can then write a pushVC method, which takes as argument a UIViewController *vc. It does a [navCt pushViewController:vc animated:YES];
Connect the button to an IBAction, which then calls the method in the app delegate, [PushVC myVC], where myVC refers to any viewcontroller in your app, in this case table view 1.
In this table, on didSelectRow... event you can use the same method to push the sub-view table view 2.
I think this is minimum code if you are unsure about iPhone app design. Either way, I hope it gives some ideas.
You should read about UINavigationController, UITabBarController, UIViewController.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
You almost always make one view pr. viewcontroller.

Present login screen on app startup

In my previous question on UIView animations I mentioned that I have to simulate the modal behavior for some view. Here I'll explain why and ask about some better solution.
The first view a user should see in my app is the login screen. Upon successful authentication the program checks if the user is a parent or a child (in a family). For each of these roles the app must provide different functionality.
So I designed the app like this:
Declare outlets for the login view controller and a tab bar controller (for the main part of the interface) in my AppDelegate.
In the application:didFinishLaunchingWithOptions: method
Set the rootViewController of the main window to the login view controller.
Make AppDelegate the delegate for the login controller, so it can send notification when it's done its job.
When AppDelegate receives the message on successful login, it determines whether the user is a parent or a child, instantiates the set of view controllers that provide corresponding functionality and passes them to the tab bar controller.
At last AppDelegate switches the rootViewController of the main window to the tab bar controller.
Certainly the user can logout, then the rootViewController is switched back again to the login controller.
I would like to present and dismiss the login screen as if it is a modal view, but AppDelegate only has a bare window, thus I don't have an object to send presentModalViewController: to. This brings up a question:
First of all, is it a good design?
And if it is, how do I simulate a modal behavior correctly?
I think you're on the right track.
However, I always try to get out of the app delegate as soon as I can, leaving it only to do application-level things (like respond to notifications, go in and out of background). In this case, doing so will help you.
In the appDelegate, create a new UIViewController class, something like "startUpController".
Add it's view to the app window.
Then in your startUpController, do everything that you used to do in the app delegate (login, tab bar setup, etc.).
And now, since you're in a view controller, you can presentModalViewController to your hearts content.
Hii,
you should refer this
http://code.google.com/p/tweetero/
https://github.com/jbrien/WordPress-iPhone
Hope this helps!

ViewController data sharing

So I have two view controller that I load on the app delegate when the app loads. One is for a login page where I have a username and password and the other one is a UITabBarViewController. After the user login, I just remove the login view and therefore showing the UITabBarViewController. The problem is that in my UITabBarViewController, I need the username and password from the ViewController. How can I solve this?
ADDITIONAL INFO:
Here's basically what I want to do:
Application starts with an Logon on page: User ID, Password and Logon button
On clicking the logon button, after validating the credentials, we've to take the user to the next screen with
an Navigation Bar on the top (essentially an UINavigationController)
Table view
Tab Bar in the bottom
Now after logging in, I want all the ViewControllers in the UITabBarViewController to be able to get the username and password that the user enters in the first login screen.
I think the best design is to have the your controller for the tab bar present a modal view controller for login. The controller tab bar would then be the delegate of the LoginViewController and the LoginViewController would notify its delegate when the login is complete. When the login is completed successfully then the controller for the tab bar can dismiss the LoginViewController.
Now I wrote this code after you updated the answer. You can figure out how to add the UINavigation bar and table views your self. The question is about passing data between view controller not me answering how to through a bunch of views together. I highly recommend to iTunes U course from Stanford on iOS programming if you want to learn more about putting many views and controllers together for a complete app.
I provide a full, complete and working example demonstrating proper use of delegates to share data between the LoginViewController and a UIViewController (In your case the UIViewController would be replaced by your tab bar controller). I also demonstrate how to use NSUserDefaults to save this data which is accessible from elsewhere is the app.
All the code for the example can be found here.
1 Use root controller to share the data.
You can put the data in your root controller and the root controller creates two view.
The root controller can transfer the data to its child views.
2 Or use class constructor.
When you create the views, you can give them parameters with data.
That is not a big Problem.
You can create two NSString variables in the appDelegate class and set the property to them. So that you can access those variable in the entire project.
You will set the values in the login page and you will access those in the tabBarController.
Thats it.
Reagards,
Satya