How to do horizontal slice between views? - iphone

I'm looking for some advice about the best way to create a multi-view iPhone application. This app will slice left to right and right to left when a it goes from one view to another. Very similar to how a navigation-based application but without the navigation top bar.
I'm doing some tests using this code:
- (IBAction)goToSettings:(id)sender {
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:#"SettingsView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
something like UIModalTransitionStyleCoverHorizontal which doesn't exist.
So, I'm trying to do transitions, but now sure if that's the best way to do it, in terms of memory management, etc.
In summary, my application will have ~8 views, and I need to be able to navigate between them, going left to right into details, and go back to the left (previous view). What is the best way to do it?
Thanks in advance.

The navigation bar is optional in a navigation-based application. UINavigationController has a - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated method.
If for some reason that won't work, an alternative might be a paging UIScrollView, but that would be more hacky and more work to get what UINavigationController already gives you.

Related

How do I call the SecondViewController on Xcode?

I'm new to programming on Xcode and can't really find out how to call the SecondViewController window by pressing a button. The button is called Ingredients; I tried entering "-(IBAction)Ingredients:(id)sender; in the ViewController.h and but then saw that there was the FirstViewController.h and SecondViewController.h, same with First and second ViewControllers.
Anyways, what I wanted to do was be able to click the "Ingredients" button and make it go to a completely different window, with a different background, and other texts as the first one. I'm not sure if I'm explaining myself correctly :(. Let me try an Image:
First of all, get some basic knowledge about Objective C. Go to Apple developer website and you will get tons of tutorials & sample codes to learn.
Now, for your question:-
In firstViewController.m
First import SecondViewController.h
On button click:-
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
As I can see you are not using story board so simply call:
FLSecondViewController *object = [[FLSecondViewController alloc] initWithNibName:#"FLSecondViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:object animated:YES];
Why go for another window? a View controller may be enough,set up a navigation controller and push the second viewcontroller.
a sample tutorial on navigation controller
- (IBAction)Ingredients:(id)sender
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentModalViewController:secondViewController animated:YES];
}
edited: Typical an iOS app has only one window which acts as a container for views, so you work most of time only with views. Change one view with another depend on desired content to be presented.

How to Animate iPhone New Screen towards Left

I am new bee in iPhone and just started development in it.
Learning a lot because of friends like you!
I just learnt how to go to another screen from current screen and i Did well due to tutorials from Internet.
But now the problem is when new screen comes up it animates from Bottom to Up and when we click DONE button to close the screen it goes from Up to Down. I have seen many applications in iPhone that animate the new screen from Right to Left and again from Left to Right.
What Piece of code do i need to add into the following to animate it toward left.
Please guide me Friends
MainScreen *screen = [[MainScreen alloc] initWithNibName:#"MainScreen" bundle:[NSBundle mainBundle]];
self.mainScreen = screen;
[self presentModalViewController:mainScreen animated:YES];
There are four different ModelTransitionsFor View Controllers.
You can set those for
screen.modalTransitionStyle = UIModalTransitionStylePartialCurl;
There are 3 other Styles you can check on Apple Site Link
If you need to do something like Navigation Style. you need to push your view controller to navigation stack.
[self.navigationController pushViewController:screen animated:YES];
Instead of this
[self.navigationController presentModalViewController:yourView animated:YES];
use this
[self.navigationController pushViewController:yourView animated:YES];
If you have Navigation based app then replace code with below.
MainScreen *screen = [[MainScreen alloc] initWithNibName:#"MainScreen" bundle:[NSBundle mainBundle]];
self.mainScreen = screen;
[self.navigationController pushViewController:screen animated:YES];
There are few modal view transitional styles available. Check apples documentation on this.
Also there are few uiviewtransitionanimation styles also described neatly in apple's guide.

How come presentModalViewController is not working the second time?

I am using a tab based application that shows a presentModalViewController called "overview" that has 2 buttons on it .
In order to call it I am using the following code in app delegate:
Overview *overview = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
[self.tabBarController presentModalViewController:overview animated:YES];
When overview shows up, it has a button called that gets clicked and I am using the following code:
-(IBAction) btnLoginPressed{
[self dismissModalViewControllerAnimated:YES]; //get rid of view
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self.tabBarController presentModalViewController:login animated:YES];
[login release];
}
However the login prsentModalViewController never shows up. Can someone explain why and what I can do to show it?
Thanks
When you present a modal view controller, you do it from the view controller currently in the view.
Assuming your second modal display of a view controller is happening in Overview.m change your code to the following:
-(IBAction) btnLoginPressed {
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self presentModalViewController:login animated:YES];
[login release];
}
You don't need to dismiss Overview first, and in fact you shouldn't as it the animations won't work in conjunction with each other.
When you ultimately dismiss login (or however deep you want to go), you send dismissModalViewController:animated: as high up as you need to. To get back to the tab bar's controller use:
[self.tabBarController dismissModalViewController:animated]
It would be well beyond the scope of your question and the time I have to answer but you should take some time and really study the docs on implementing View Controllers. I definitely recommend following Apple's code style guidelines as one suggestion to make your code much more readable (e.g. overviewViewController vs overview). It's also clear you're just learning so keep at it.

Problem with getting a modalViewController to appear

I've been fighting with this for hours. I've searched around everywhere and just can't seem to find the solution to my problem. I'm pretty sure I'm just lacking some key concepts here.
My AppDelegate (didFinishLaunching) basically sets up my window and invokes RootViewController:
// create our window
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setBackgroundColor:[UIColor blackColor]];
// create our rootviewcontroller
RootViewController *controller = [[RootViewController alloc] init];
// add our rootviewcontroller's view to our window
[window addSubview:controller.view];
// controller is now owned by window's view
[controller release];
// show us to the world
[window makeKeyAndVisible];
When I add controller.view as window's subview, my understanding is that RootVC's loadView will automatically get called.
In RootVC loadView, I create a tabBarController, each tab having a navigationController and it's own viewController. All that is working fine.
In RootVC viewDidLoad, I'm checking to see if this is the first time a user is running this app, and if so, I want to throw up a modal welcome screen. This is the part I'm having trouble with.
I'd like to keep as much code out of the RootVC's viewDidLoad method, and ideally would be able to accomplish what I want with this:
WelcomeViewController *welcome = [[WelcomeViewController alloc] init];
[self presentModalViewController:welcome animated:true];
[welcome release];
Obviously this isn't working. WelcomeVC's loadView hasn't been run yet because I haven't explicitly set it's view property. I've played around with a bunch of different solutions (welcome.view - [[UIView....], using WelcomeVC's init method to set self.view) but I just can't seem to get that modal to pop up.
How should I accomplish what I'm looking for? What are the best practices, and what's the best solution to keep my code tight and tidy?
I'm stuck, so hopefully your solution will allow me to continue developing my app!
Although the problem is not so simple, the solution is. You have to wait until the main view appears. So check the condition and present your modal view in viewDidAppear method, not in viewDidLoad method.

how can I call a screen with a button action (xcode)?

I am developing a Window Based app for iPhone. I use Interface Builder to build Interface. I want to call a new screen with a Button Action. How can I call the screen with Button action ?
By pushing the new controller onto the top of the stack of windows. For example:
EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:#"EnterName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];
Apple has an extraordinary amount of sample code, and this question (as well as many others) could easily be solved by simply visiting Apple's iPhone dev site.
iPhone Dev Site
If you are using a navigation controller, push it onto the navigation controller's stack, as alamodey suggested.
If you want it to be a modal controller (that is, slide up from the bottom and cover the previous controller's view, like the Bookmarks screen in Safari), present it as a modal view controller:
[self presentModalViewController:myNewController animated:YES];
When you want to bring the old controller back, dismiss the modal view controller. From inside the modal view controller:
[self.parentViewController dismissModalViewControllerAnimated:YES];
If you don't want to do either, just remove the current controller's view from the window and add the new controller's:
UIView * containingView = self.view.superview;
[self.view removeFromSuperview];
[containingView addSubview:myNewController.view];
If you go this route, you may want to look into +[UIView beginAnimations:context:], +[UIView setAnimationTransition:onView:], and +[UIView commitAnimations] (if I recall the method names correctly--check the documentation) to animate the transition. You should almost always animate any switch between screens in iPhone OS.
(work in .m class)
#import "classtocall.h"
- (IBAction)ButtonPressed:(id)sender
{
classtocall *mvc = [[classtocall alloc]initWithNibName:#"classtocall" bundle:nil];
[self presentModalViewController:mvc animated:NO];
}
(for window based application)
define in .h class
- (IBAction)ButtonPressed:(id)sender;
where "classtocall" is the class you want to call.
you just need to download sample applications from XCode help. Try Elements and UIcatalog. There are also other - type 'pushViewController' or 'addSubview' adn 'makeKeyAndVisible' in help and download samples
nextscreenViewController *login = [[self storyboard] instantiateViewControllerWithIdentifier:#"nextscreenidentifier"];
nextscreenidentifier.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController: nextscreenidentifier animated: YES];