I'm new on IOS platform and after study a little about how does it works, i had one doubt about how to call a new class/view and overlay the current view when a button is pressed. In android i do:
Intent intent = new Intent(a.class, b.class);
startActivity(intent);
Searching on internet, i noticed that i have to use navigation bars to do it. I start an app with tab bar controller and putted a navigation controller. I used the code below:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:#"Dicas"];
[self.navigationController pushViewController: myController animated:YES];
and the return:
There is a way to overlay the current view? I always have to use navigation bars to call another class (use bottom e upper controllers will make my app ugly)?
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To hide tab bar:
yourViewController.hidesBottomBarWhenPushed = YES;
You can also call another viewController by using presentViewController function of a viewController class.
[self presentViewController: myController animated:YES completion:nil];
As you said u want to overlay your current view so not sure but You can show your view controller using model view like this
yourViewController *secView = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
[secView setModalPresentationStyle:UIModalPresentationPageSheet];//u can use different UIModalPresentationStyle
[secView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.navigationController presentViewController:secView animated:YES completion:nil];
Above one will show your view controller over existing view controller, once presented you need to make provision to dismiss this modal view.
Simple way to present new class or ViewController like this..
ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:view animated:YES completion:nil];
Related
I have a view controller like in the image below:
And I am trying to present this view controller from another view controller like so:
LHPDFFile *vc = [[LHPDFFile alloc] init];
vc.previewItemURL = self->_previewItemURL;
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:vc];
[self presentViewController:navBar animated:YES completion:nil];
This works, however my buttons are not appearing :(
It appears that the code above is creating a Navigation Controller instead of using mine with the buttons. What am I doing wrong?
Try instantiating your view controller with the storyboard. Something like:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
LHPDFFile *vc = (LHPDFFile *)[storyboard instantiateViewControllerWithIdentifier:#"<id of your view controller in the storyboard>"];
Calling the empty init method leads to empty instantiation of the view, because you have never mentioned that it should use this storyboard's this view controller. More details here.
You init none of your controllers from storyboard! Those buttons belongs to file view controller. You should init that controller from storyboard instead of call init.
MyViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier: #"MyViewControllerStoryBoardID"];
UINavigationController *navBar = [[UINavigationController alloc]initWithRootViewController:vc];
[self presentViewController:navBar animated:YES completion:nil];
In my application i am launching one screen using present UIModalViewController and on that screen I have oneUIButton, if we click on that UIButton alert will come then select yes on alert view now we have to call another view usingpushviewcontroller. But screen is not coming if we use below code can any one help me.
[self.navigationController pushViewController:requestViewController animated:YES];
Try with one root navigation controller and then present your controller modally as follows :
FirstViewController *firstView=[[FirstViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstView];
[self presentViewController:navigationController animated:YES completion:nil];
and then for push another view as follow :
SecondViewController *secondView=[[SecondViewController alloc]init];
[self.navigationController pushViewController:secondView animated:YES];
It will work first using present modal viewController and then using push navigation viewControllers on to the stack.
I'm trying to move from 1st view controller -> 2nd view controller. However, it seems nothing is happening.
It is mainly from a sign-in page, so I don't need to get back to that page once I have a successful login. I'm trying right now from a button just to check.
I have 2 classes.
signInPage
optionsScreen
I need to go from 1 > 2
Inside signInPage.m
#import "optionsScreen.h"
- (IBAction)moveToNext:(id)sender {
optionsScreen *aSecondPageController =
[[optionsScreen alloc]
initWithNibName:#"optionsScreen"
bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:YES];
// [aSecondPageController release];
}
Screenshot of story board
https://drive.google.com/file/d/0B1y7ao4cGAYKaU0yRlVxcVg2bzA/edit?usp=sharing
Solution:
- (IBAction)moveToNext:(id)sender {
NSString * storyboardName = #"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"optionsScreen"];
[self presentViewController:vc animated:YES completion:nil];
}
In storyboard add navigation view controller. As root view controller - perhaps by default it is table view controller, so remove it - set up 1st view controller. Adding navigation controller you can push to navigation stack as many view controllers as you want.
I think what you're trying to do is present the view controller modally, not push it onto the stack (which doesn't exist). Instead you should just do this. This will not show a back button by default so you'll have to add one manually:
optionsScreen *aSecondPageController = [[optionsScreen alloc] initWithNibName:#"optionsScreen" bundle:nil];
[self presentViewController:aSecondPageController animated:YES completion:nil];
To go back, in your optionsScreen view controller, you'll need some sort of back button right? So you can do this in your viewDidLoad:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(backPressed:);
Then you'll have to create a new method called backPressed:
-(void)backPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
Edit: it turns out you were trying to do what I explained above. I will leave the navigation controller bit for future reference.
If you are trying to use a navigation controller to push your options, which will give you a back button by default, then first, in your storyboard, click your sign in view controller, then at the menu bar at the top go to Editor > Embed In... > Navigation Controller. Then in your view controller switch method, you can do what you were trying before
optionsScreen *aSecondPageController = [[optionsScreen alloc] initWithNibName:#"optionsScreen" bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:YES];
I have a view controller that has a button on it. The button is the Privacy Policy. When it's clicked it goes to the proper IBAction and I create the privacy controller.
- IBAction ...
{
PrivacyPolicyViewController *privacy = [[PrivacyPolicyViewController alloc] init];
.....
}
I want to create a modal view of the privacy controller that has a UIWebView that animates itself upward and a back button to close it in ios 7. The ways I see online all are ios 6 and seem deprecated.
Use something like this:
// assuming your controller has identifier "privacy" in the Storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PrivacyPolicyViewController *privacy = (PrivacyPolicyViewController*)[storyboard instantiateViewControllerWithIdentifier:#"privacy"];
// present
[self presentViewController:privacy animated:YES completion:nil];
// dismiss
[self dismissViewControllerAnimated:YES completion:nil];
[self presentmodalviewcontroller:vc]; has been deprecated.
you can try for
[self presentViewController:viewController animated:YES completion:nil];
it will work for you..
If you are using Storyboards, you can use a segue to present a modal view controller as well, and do it programmatically.
In your storyboard, ctrl+drag from the File's owner icon in the bar under the starting view to the view you want to present modally, let go and select "modal".
click on the segue icon, and then in the Attributes inspector, give it an identifier, like "toNewView".
in your starting view controller's .m file, use this code to perform the modal segue: [self performSegueWithIdentifier:#"toNewView" sender:self];
It's a nice clean way to do it because you don't have to import a .h file to instantiate the second controller object for the presentViewController method.
To dismiss it, you just use an unwind segue.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
taskQueeDetails *privacy = (taskQueeDetails*)[storyboard instantiateViewControllerWithIdentifier:#"taskQueeDetails"];
// Present the modal
[self presentViewController:privacy animated:YES completion:nil];
use the code and change the string instantiateViewControllerWithIdentifier:#"taskQueeDetails"];
it will work fine
In my app i present a UINavigationController modally with a UIViewController as its rootViewController. I do it in form style. I added a second UIViewController which is also in form style and i can push to it fine. However when i perform a popViewController action after the second UIViewcontroller gets popped onto the first, the whole modally presented UIViewController gets dismissed. However i don't perform any dismissing and the dismissing function doesn't get triggered by accident either.
Any ideas why it's happening?
Sincerely,
Zoli
EDIT:
That's how i'm presenting the modal viewcontrollers with a navcontroller:
if(!welcomeScreenAlreadyPresented) {
welcomeScreenViewController = [[WAWelcomeViewController alloc]init];
}
welcomeScreenNavController = [[UINavigationController alloc]initWithRootViewController:welcomeScreenViewController];
[welcomeScreenNavController setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[welcomeScreenNavController setModalPresentationStyle:UIModalPresentationFormSheet];
[welcomeScreenNavController setNavigationBarHidden:YES animated:NO];
[self.navigationController presentViewController:welcomeScreenNavController animated:YES completion:nil];
That's how i'm navigation in WAWelcomeViewController.m
registerViewController = [[WARegisterViewController alloc]init];
[self.navigationController pushViewController:registerViewController animated:YES];
And in WARegisterViewController.m that's how i pop back
[self.navigationController popViewControllerAnimated:YES];
What you need to do is put the viewController you want to push inside another UINavigationController.
registerViewController = [[WARegisterViewController alloc]init];
UINavigationController *modalNavigationController = [[UINavigationController alloc] initWithRootViewController:registerViewController]; // autorelease if you are not using ARC
[self presentViewController:navController animated:YES completion:^{}];
You might want to add the modalNavigationController as a property to later call popViewControllerAnimated: on it.