modalPresentationStyle not working in modal view in iOS5 - ios

I want to display a popup window in iPad using the UIView's presentModalViewController method in iOS5.
Even though I set the modalPresentationStyle to UIModalPresentationFormSheet, it only displays as full frame size.
I used the same code in iOS4 before, and it can display as a popup window. How to fix it in iOS5?
DetailViewController *d = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
self.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:d animated:YES];
Thanks.

Have you try
d.modalPresentationStyle = UIModalPresentationFormSheet;
instead of
self.modalPresentationStyle = UIModalPresentationFormSheet;

In iOS5, the modal view should be used as below.
DetailViewController *d = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:d];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navigationController animated:YES];

Related

pushfrontviewcontroler open blank screen

I need to set to root for second view controller through SWRevealViewController. But when I call pushFrontViewcontroler it become a blank screen. All my label that I defined in storyboard is missing. But the external xib i include is properly display. Am I missing something? Please enlighten me on how to solve this. Below is the code i use to call the second view controller.
SWRevealViewController *revealController = self.revealViewController;
ImageDetailViewController *imageViewController = [[ImageDetailViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imageViewController];
[revealController pushFrontViewController:navigationController animated:YES];
I also try using this but still failed
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imageViewController];
[self.revealViewController setFrontViewController:navigationController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
Storyboard
Your main problem is the instantiation of your imageViewController
ImageDetailViewController *imageViewController = [[ImageDetailViewController alloc] init];
if you do something like this
ImageDetailViewController *imageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"MyImageViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imageViewController];
[revealController pushFrontViewController:navigationController animated:YES];
this works perfect, but I still recommends you have your navViewControllers on your storyboard and change them like this code
- (void) goMainViewControllerAction
{
UINavigationController* navigationController = [self.storyboard instantiateViewControllerWithIdentifier:#“MainNavViewController”];
[self.revealViewController pushFrontViewController:navigationController animated:YES];
}
//
- (void) goImageViewControllerAction
{
UINavigationController* navigationController = [self.storyboard instantiateViewControllerWithIdentifier:#"MyImageNavViewController"];
[self.revealViewController pushFrontViewController:navigationController animated:YES];
}
I hope this helps you

Push View from Presented View Controller in iOS

In Short :
How can I PushViewController from Presented ViewController ?
In Brief :
I have MainViewController, In which I have one button on click of button, I am presenting a view called LoginViewController.
On this page (LoginViewController), I again have button, on click of that, I try to push my view controller(called HomeViewController) it doesn't pushes.
Here is my code snippet,
MainViewController.m
- (IBAction)LoginClicked:(id)sender {
LoginViewController *vc = [[LoginViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
}
LoginViewController.m
- (IBAction)buttonActionMethodOnLoginView:(id)sender{
NSLog(#"viewControllers %#",APPDELEGATE.nav.viewControllers);
//LoginViewController is not in this array
HomeViewController *obj = [[HomeViewController alloc] init];
[self.navigationController pushViewController:obj animated:YES];
}
But it did not works for me. Also, I printed a stack of view controllers before pushed, but it doesn't have LoginViewController. So, without adding LoginViewController into a stack of view controllers, How can I pushed to HomeViewController from LoginViewController ?
When I getBack from HomeViewController, then LoginViewController should get opened..
Is it possible using doing this single NavigationController?
Note:- Here, I have just taken an example using Login, Home and Main ViewController. But I want that into Other Screens.
hi when you are Presenting you Login view controller Just present a navigationController like:
LoginVC *loginVCObj =[[LoginVC alloc]initWithNibName:#"LoginVC" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVCObj];
[self presentViewController:nav animated:YES completion:nil];
Now your PresentedViewController is An navigtioncontroller
now you can simply push to your Home VC
HomeViewController *obj = [[HomeViewController alloc] init];
[self.navigationController pushViewController:obj animated:YES];
Hope it will helpful for you
LoginViewController should not be pushed to navigation controller stack. Let me describe below "why".
Our MainViewController should be on the stack - you always want to go back there.
// AppDelegate.m (only if you don't use storyboards, if you do - you don't need to copy this part of code)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// create the window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window makeKeyAndVisible];
// set view controllers
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc] init]];
[self.window setRootViewController:navigationController];
}
On specific action show LoginViewController. You don't want the user to be able to tap back and go to MainViewController. Later, you won't want user to go back to LoginViewController. Because of this, you need to present it as modal:
// inside `MainViewController.m`
- (IBAction)myCoolActionToShowLogin:(id)sender {
[self presentViewController:[[LoginViewController alloc] init] animated:YES completion:nil];
}
Now we can see LoginViewController. When user completes the login, dismiss it and present HomeViewController:
// inside `LoginViewController.m`
- (IBAction)myAwesomeActionToShowHome:(id)sender {
UINavigationController *navigationController = (UINavigationController *)[UIApplication.sharedApplication.keyWindow rootViewController];
[navigationController pushViewController:[[HomeViewController alloc] init] animated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
NOTES:
As you may notice, myAwesomeActionToShowHome: expects you have navigation controller as your rootViewController. This is working, but should be nicer - you should check if that navigation is in fact navigation controller instead of casting it. Or you may create a delegate or block to push new one. This is the fastest, easiest working solution, which should be improved later.
You really should read: Apple Developer -> "View Controller Programming" documentation, as these are the core fundamentals you should know to develop & design UX correctly.
Here is the working demo sample.
You can't push from a presented view controller. I suggest, you should maintain your navigation hierarchy.
For that, from your MainViewController, you should present LoginViewController and you should pass navigation controller for the MainViewController.
- (IBAction)openLogin:(id)sender {
LoginViewController *loginVC = (LoginViewController *) [self.storyboard instantiateViewControllerWithIdentifier:#"login"];
[loginVC setReferencedNavigation:self.navigationController];
[self presentViewController:loginVC animated:YES completion:nil];
}
Then inside LoginViewController, you should push to HomeViewController like this,
LoginViewController.h
#interface LoginViewController : UIViewController {
UINavigationController *refNavigationController;
}
- (void) setReferencedNavigation:(UINavigationController *)refNavCon;
LoginViewController.m
- (void) setReferencedNavigation:(UINavigationController *)refNavCon {
refNavigationController = refNavCon;
}
- (IBAction)openHome:(id)sender {
[self dismissViewControllerAnimated:YES completion:^{
UIViewController *homeVC = [self.storyboard instantiateViewControllerWithIdentifier:#"home"];
[refNavigationController pushViewController:homeVC animated:YES];
}];
}
By doing this, it will be look like, you're pushing from LoginViewController but in reality you're pushing from MainViewController.
You can customize this approach to maintain animation and UI for this flow.
1) present a navigation controller with itsroot view controller` set as view controller .
- (IBAction)LoginClicked:(id)sender
{
LoginViewController *loginViewController = [LoginViewController alloc] init];
UINavigationController *navController = [UINavigationController alloc] initWithRootViewController:loginViewController];
[self presentViewController:navController animated:YES completion:nil];
}
- (IBAction)buttonActionMethodOnLoginView:(id)sender
{
HomeViewController *obj = [[HomeViewController alloc] init];
[self.navigationController pushViewController:obj animated:YES];
}
Hope it will work for you.
The problem is that LoginViewController has no navigation controller. Then you give it one.
MainViewController.m
Create a UINavigationController, put LoginViewController in to the stack and present the UINavigationController.
- (IBAction)LoginClicked:(id)sender {
LoginViewController *vc = [[LoginViewController alloc] init];
UINavigationController = nav = [[UINavigationController alloc] init];
nav.viewControllers = #[vc];
[self presentViewController:nav animated:YES completion:nil];
}
LoginViewController.m
- (IBAction)buttonActionMethodOnLoginView:(id)sender{
HomeViewController *obj = [[HomeViewController alloc] init];
[self.navigationController pushViewController:obj animated:YES];
}
Dismiss
Call dismissViewControllerAnimated in your MainViewController.
For Swift 3.0
Present your view controller as a new rootViewController
let navController = UINavigationController.init(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "SignInViewController"))
self.present(navController, animated: true, completion: {})
Now push your view controller from presented view controller
self.show(self.storyboard!.instantiateViewController(withIdentifier: "SignUpViewController"), sender: self)
Create a UINavigationController instance
[[UINavigationController alloc] initWithRootViewController:[[LoginViewController alloc] init]]
Present that navigationController and then push whatever VC you want to.
MainViewController.m
- (IBAction)LoginClicked:(id)sender {
LoginViewController *vc = [[LoginViewController alloc] init];
UINavigationController *loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:loginNav animated:YES completion:nil];
}
LoginViewController.m
- (IBAction)buttonActionMethodOnLoginView:(id)sender{
NSLog(#"viewControllers %#",APPDELEGATE.nav.viewControllers);
//LoginViewController is not in this array
HomeViewController *obj = [[HomeViewController alloc] init];
[self.navigationController pushViewController:obj animated:YES];
}
You have to Push from your firstView (MainViewController), but you can use animation same as PresentView and DismissView. Use following code for this :-
For Push (on MainViewController)
LoginViewController *VC = [[LoginViewController alloc]init];
CATransition* transition = [CATransition animation];
transition.duration = 0.3f;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[[[UINavigationController alloc] initWithRootViewController:VC] pushViewController:VC animated:NO];
//[self.navigationController pushViewController:VC animated:NO];
For Pop (on LoginViewController)
CATransition* transition = [CATransition animation];
transition.duration = 0.3f;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
Using this code, you can get animation same as Present-Dismiss ViewControllers. Refer this answer for more details.
And after that, you can use your code for Pushing LoginViewController to HomeViewController
Hope, this is what you're looking for. Any concern get back to me. :)
This is very simple code for present view controller and push view controller.
- (IBAction)LoginClicked:(id)sender {
LoginViewController *objLogicVC = [LoginViewController alloc] init];
UINavigationController *navPresent = [UINavigationController alloc] initWithRootViewController:objLogicVC];
[self presentViewController:navPresent animated:YES completion:nil];
}
- (IBAction)buttonActionMethodOnLoginView:(id)sender{
HomeViewController *objHomeVC = [[HomeViewController alloc] init];
[self.navigationController pushViewController:objHomeVC animated:YES];
}
simply put this code in objective c on button action
UIViewController *yourViewControllerName = [self.storyboard instantiateViewControllerWithIdentifier:#"yourViewControllerName "];
[[self navigationController] pushViewController:yourViewControllerName animated:YES];

navigation controller without using story boards

SecondViewController *testAppViewController2Obj =[[SecondViewController alloc]initWithNibName:#"TestAppViewController2" bundle:nil];
[self.navigationController pushViewController:testAppViewController2Obj animated:YES];
ContainerViewController *container = [[ContainerViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 65)];
container.navigationItem.title = #"Frames";
self.window.rootViewController = nav;
i hope it works
In order to push a new view controller you should first create a view controller, VC1, link it with a navigation controller and then link the navigation controller to the rootViewController in the AppDelegate
#AppDelegate
FirstViewController *VC1 = [FirstViewController new];
UINavigationController *nVC = [UINavigationController alloc] initWithRootViewController:VC1];
self.window.rootViewController = nVC;
Then when VC1 gets pushed, you can create another view controller and push it like this:
#Now in VC1
SecondViewController *VC2 = [SecondViewController new];
[self.navigationController pushViewController:VC2 animated:YES];

Present UINavigationController and show additional (second) title above navigation bar

I wonder if it is possible to show additional title above navigation bar like it is done in iOS7 WiFi settings (Other Network) - Enter network information.
This is how I present my navigation controller:
UIViewController *vc = [UIViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentViewController:navController animated:YES completion:nil];
I was looking for a solution but I haven't found anything.
Set the prompt of the view controller's navigationItem:
UIViewController *vc = [UIViewController new];
vc.navigationItem.prompt = #"Enter network information";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentViewController:navController animated:YES completion:nil];

iPad center custom modal view

I have an application with custom modal view controller and this controller is inside navigation controller here is my code:
CalendarViewController *calendarViewController = [[CalendarViewController alloc] initWithNibName:#"CalendarViewController" bundle:nil];
[calendarViewController setDelegate:self];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:calendarViewController];
[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
[navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];
navigationController.view.superview.frame = CGRectMake(0, 0, 630, 555);
navigationController.view.superview.center = self.view.center;
Problem is that this navigation controller is not center on screen. Location of this screen is right side of ipad. Is there a solution how center this custom controller. Thanks a lot.

Resources