I'm trying to implement a UIModalTransitionStylePartialCurl on a viewController to present a partial view of ViewController2 (I am using xCode 4.6 with storyBoards for a universal app). The following code does animate the UIModalTransitionStylePartialCurl but shows only a black window underneath. So, it works (no crash) but it won't present/show the second view ??
ViewController2 *v2 = [[ViewController2 alloc]init];
v2.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:v2 animated:YES completion:NULL];
You haven't initialized v2 . you should use this :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Your_storyboard_name" bundle:nil];
ViewController2* v2 = [storyboard instantiateViewControllerWithIdentifier:#"Your_view_controller_identifier_from_storyboard"];
v2.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:v2 animated:YES completion:NULL];
Do any additional checks to see if it's iPad or iPhone and fill the information as is required.
Related
I need to present a view controller from app delegate.
When a phone notification comes in, I am able to decide which one of 3 view controllers (named ForumViewController, BlogViewController & NewsViewController) should be presented by analyzing the 'userInfo' in the method 'didReceiveRemoteNotification'.
But when i try to present the appropriate view controller using storyboards or the code below:
self.viewController = [[MembersViewController alloc] initWithNibName:#"MembersViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
Then, the app gives the error 'Warning: Attempt to present whose view is not in the window hierarchy!'. Also it gets stuck on a particular view controller.
Please keep in mind that the view controllers that I am trying to present are not part of the flow when the app starts (the flow is LogoViewController -> SplashViewController -> HomeViewController).
The HomeViewController & MembersViewController are essentially the main menu pages for public & private viewing. Here I have to display something to the viewer.
choice-1
using push
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
MembersViewController *vc = [navController.storyboard instantiateViewControllerWithIdentifier:#"MembersViewController"];
[navController pushViewController:vc animated:YES];
using present
MembersViewController *root = (MembersViewController *)self.window.rootViewController;
UIViewController *vc = [root.storyboard instantiateViewControllerWithIdentifier:#"MembersViewController"];
[root presentViewController:vc animated:YES completion:NULL];
upadted
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MembersViewController* pvc = [mainstoryboard instantiateViewControllerWithIdentifier:#"MembersViewController"];
[self.window.rootViewController presentViewController:pvc animated:YES completion:NULL];
Loading a view controller from the storyboard:
[self performSelector: #selector(ShowModalViewController) withObject: nil afterDelay: 0];
-(void)ShowModalViewController{
NSString * storyboardName = #"MainStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER_OF_YOUR_VIEWCONTROLLER"];
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
}
Identifier of your view controller is either equal to the class name of your view controller, or a Storyboard ID that you can assign in the identity inspector of your storyboard.
I've got the iPhone working fine with creating a segue programmatically.
e.g.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
bundle:nil];
FooBarViewController *foobarViewController = (FooBarViewController *)[storyboard instantiateViewControllerWithIdentifier:#"foobarViewControllerID”];
[self.navigationController pushViewController:foobarViewController animated:YES];
Now I'm trying to do something similar on the iPad storyboard.
The goal being to programmatically change the detail view to a view on the storyboard.
I thought maybe:
[self.splitViewController.navigationController presentViewController:foorbarViewController animated:NO completion:nil];
However this doesn't work. Any suggestions?
I believe I've solved my own question with the following function:
- (void) presentDetailView : (UIViewController *) viewcontroller {
UINavigationController *detailNavCtrl = [[UINavigationController alloc] initWithRootViewController:viewcontroller];
detailNavCtrl.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
detailNavCtrl.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[[[self.splitViewController viewControllers] lastObject] presentViewController:detailNavCtrl animated:NO completion:nil];
}
I want to switch from the main view to the login view modally.
I use the following code in the main view controller to do this:
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:false];
loginViewController *loginView = [[loginViewController alloc] init];
loginView.modalTransitionStyle= UIModalTransitionStyleCoverVertical;
[self presentViewController:loginView animated:YES completion:nil];
}
The main screen is displayed fine. However, when the switch happens, the resulting view is a plain black screen. Why is this happening?
do this
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"your story board name" bundle: nil];
loginViewController *loginView = [mainStoryboard instantiateViewControllerWithIdentifier: #"your story board identifier"];
loginView.modalTransitionStyle= UIModalTransitionStyleCoverVertical;
[self presentViewController:loginView animated:YES completion:nil];
I'm looking for a way to present a modal view over my current UIViewController to basically show a UIActivityIndicator and force users to wait while data is being loaded.
in BaseViewController.m (base class of all my UIViewControllers):
// show loading view
-(void) showLoading
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
LoadingViewController *loading = [storyBoard instantiateViewControllerWithIdentifier:#"loadingView"];
loading.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.7];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:loading animated:NO completion:nil];
}
This works great, but how can I go back to the background view after the loading view should be done?
Need a stopLoading method to go back to the original view:
// stop loading
-(void) stopLoading
{
// code here
}
If I try to present a new view after I present the loading view like so:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UIViewController *view = [storyBoard instantiateViewControllerWithIdentifier:#"loadingView"];
[self presentViewController:view animated:YES completion:nil];
The debugger gives Warning:
Attempt to present PropertyPickerViewController: 0x8af6010 on ViewController: 0x8ab23c0 which is already presenting LoadingViewController: 0x8acf530.
Try:
[self dismissViewControllerAnimated:YES completion:nil];
In fact, I'm not sure that it'a great idea to present new controller with animated gif.
The best option is (imo) show UIActivityIndicator + place a view on top on all other views to prevent user from clicking anything.
You must [self dismissViewControllerAnimated:YES completion:nil] first.
Check the Apple Documentation.
- (IBAction)submitButtonClicked:(id)sender{
NSLog(#"here");
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init];
[self presentViewController:sfvc animated:NO completion:NULL];
}
I am trying to open a new page when a user clicks the submit button in the app. However, this opens completely black screen with nothing on it. How do I make it open the viewController instead ?
You are not entering the nib name for the user Interface:
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] initWithNibName:#"SuccessOrFailViewController" bundle:nil];
[self presentViewController:sfvc animated:NO completion:NULL];
For storyboard this is the way to go:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:sfvc animated:YES];
Swift
var next = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! DashboardController
self.presentViewController(next, animated: true, completion: nil)
don't forget to set ViewController StoryBoard Id in StoryBoard -> identity inspector
Incase anyone else finds this, make sure you haven't set self.view.backgroundColor = UIColor.clearColor() in the view to be shown... This solved it for me.
For Storyboard iOS7
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
I've had this happen after adding and deleting View Controllers in the Storyboard and forgetting to update the View Controller with the latest Storyboard identifier.
For example, if you are programmatically moving to a new View Controller, like this (note Identifier in the code is "FirstUserVC"):
let firstLaunch = (storyboard?.instantiateViewControllerWithIdentifier("FirstUserVC"))! as UIViewController
self.navigationController?.pushViewController(firstLaunch, animated: true)
The make sure in Interface Builder you have the Storyboard ID set like this with FirstUserVC listed in the Identity for Storyboard ID: