How to load multiple views on top of the UIViewController - iphone

How to load multiple views one after the another once this view is displayed
- (void)displayviewsAction:(id)sender
{
PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
}
Now on top of this viewcontroller how i can load multiple viewcontrollers one after the other.
Please advice.
Thanks for help.

It depends on how you want to display it. If you're using a UINavigationController, you can do something like:
[self.navigationController pushViewController:viewController animated:YES];
or, if you'd like to present it as a modal view, you can do this to support older versions of iOS:
[self presentModalViewController:viewController animated:YES];
or, if you're only targeting iOS 5, do this:
[self presentViewController:viewController animated:YES completion:NULL];
Then to dismiss the view controller, on older versions of iOS:
[self dismissModalViewControllerAnimated:YES];
or if you're only targeting iOS 5:
[self dismissViewControllerAnimated:YES completion:NULL];

I think what you are looking for is a UINavigationController. That is a kind of super-controller that can load a stack of other view controllers one after another.

Related

How can I switch between views programmatically?

I have the following problem. I want to go from a view to another view, not with a button, but writing code. I have a view in which there are, among other things, some buttons. When I press one of them runs an if - else. From else I want to go to another view.
I have tried this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];
this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
[self.view insertSubview:gOver.view atIndex:0];
and this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
[self.view addSubview:gOver.view];
but nothing worked. Any ideas ?
i also tried this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view setHidden:YES];
[self.navigationController pushViewController:gOver animated:NO];
throws exeption on
[self presentModalViewController:gOver animated:YES];
[self.view insertSubview:gOver.view atIndex:0];
[self.view addSubview:gOver.view];
Thanks in advance
DonĀ“t call [self.view removeFromSuperview]; which may cause your viewController to be deallocated, when using presentModalViewController it covers your view:
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
// gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];
If you need to hide your current view then use: [self.view setHidden: YES];
"I want to go from a view to another view, not with a button, but writing code." - did you refer this to push in storyboard or did you mean that you din't want it in a button action?
The above code works fine :
-(IBAction)buttonAction:(id)sender
{
GameViewController *game = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:nil];
game.modalTransitionStyle = UIModalTransitionStylePartialCurl ;
[self presentModalViewController:game animated:YES];
}
And hope that you doing n iPhone app and not an iPad one, in which case you need to use popOver instead of modalView

Unable to navigate to next page iPhone

I am new to iPhone developer,
I have 4 page in my Application, my Application is viewBasedApplication.
I made my 1st page(LicAppViewController) as RootViewController, here is my code.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[LicAppViewController alloc] initWithNibName:#"LicAppViewController" bundle:nil] autorelease];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
on button click i am navigation to 2nd page(PlanPage)
-(void)btnClicked{
PlanPage *viewController = [[PlanPage alloc]initWithNibName:#"PlanPage" bundle:nil];
[UIView beginAnimations:#"Flip" context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView commitAnimations];
[viewController release];
}
till now it is working fine, but when i select a row in 2nd page it crashes my application, i want to navigate to 3rd page(DetailPlanPage), here is my code
DetailPlanPage *nextController = [[DetailPlanPage alloc] initWithNibName:#"DetailPlanPage" bundle:nil];
[self.navigationController presentModalViewController:nextController animated:TRUE];
but when i write, this line:
[self.navigationController pushViewController:nextController animated:YES];
instead of:
[self.navigationController presentModalViewController:nextController animated:TRUE];
it's working fine. (I am not sure but crash of my application may be because of viewBased Application)
Thanks In Advance !
set rootview controller first
remove that code
[self.window addSubview:navigationController.view];
and include
self.window.rootViewController = navigationController;
in present modal view controller u can try like this
yourview *detailViewController = [[yourview alloc] initWithNibName:#"yourview" bundle:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(dismiss)];
detailViewController.navigationItem.leftBarButtonItem = doneButton;
UINavigationController *nav;
nav=[[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
[self presentModalViewController:nav animated:YES];
[detailViewController release];
[doneButton release];
-(void) dismiss
{
[self dismissModalViewControllerAnimated:YES];
}
Try
[self presentModalViewController:nextController animated:YES];
you would also want to set the delegate for nextController to self and add a delegate function to dismiss Modal View Controller.
The most important difference is about semantics. Modal view controllers typically indicate that the user has to provide some information or do something. This link explains it more in depth:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
When you present a modal view controller, the system creates a parent-child relationship between the view controller that did the presenting and the view controller that was presented. Specifically, the view controller that did the presenting updates its modalViewController property to point to its presented (child) view controller. Similarly, the presented view controller updates its parentViewController property to point back to the view controller that presented it. And also another link.

UIPageCurl Transition like UIPageViewController between two view controllers?

I want transition similar to UIPageViewController transistion, Is it possible to achieve it.
SecondViewController* bvc = [[SecondViewController alloc] init];
[UIView transitionWithView:self.view.window
duration:1.0f
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.navigationController pushViewController:bvc animated:NO];
}
completion:NULL];
[self.navigationController pushViewController:bvc animated:YES];
As If now I have pageCurl(up) achieved via above code. But Actually want transition like pageTurn side wise. Any way to achieve this?

add navigationbar in ABUnknownPersonViewController

ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.view.frame = CGRectMake(0, 20, 320, 400);
//unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelBtn.frame = CGRectMake(262, 6, 54,30);
[unknownPersonViewController.view addSubview:cancelBtn];
[self presentModalViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
i am using UIViewcontroller and in this code i want that a bar like navigation bar will show in upper
side of this controller so i want to put cancel button on that bar.any help?
What you should do is embed your ABUnknownPersonViewController in a UINavigationController
UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:unknownPersonViewController];
[self presentModalViewController:newNavigationController animated:YES];
[view release];
[newNavigationController release];
That way you wouldn't even have to add the button yourself, the ABUnknownPersonViewController would take care of it for you.
For more info check Address Book Programming
Hmm, the online documentation says "Important Unknown-person view controllers must be used with a navigation controller in order to function properly." So, unlike a lot of the utility view controllers, I don't think you should be invoking
[self presentModalViewController:unknownPersonViewController animated:YES];
But rather
[self.navigationController pushViewController:view animated:YES];
I think if you look at their samples, you'll see they push using the navigation controller.

How can I use UIModalPresentationFormSheet with NavigationController in iPad?

I want to use UIModalPresentationFormSheet in my app. But i'm using navigation controller. So when i writes following code it is not responding me. What should i do ?
[self.navigationController pushViewController:controller animated:YES];
Try something like this:
// assume controller is UIViewController.
controller.modalPresentationStyle = UIModalPresentationFormSheet;
Then
[self.navigationController presentModalViewController:controller animated:YES];
Check with the below sample working code.
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after
presentModalViewController targetController.view.superview.center = self.view.center;
Taken from -->
How to resize a UIModalPresentationFormSheet?