I added a UIPageViewController for instructions in my new game, and I want to dismiss the UIPageViewController after the user pressed the "GOT IT" button on the last UIViewController that connect to the UIPageViewController
I've tried this so far:
[self.pageVC dismissViewControllerAnimated:YES completion:nil];
And it doesn't remove the UIPageViewController, Why that?
And how can I dismiss it?
In order to show/present the UIPageViewController I do this:
[self addChildViewController:self.pageVC];
[self.view addSubview:self.pageVC.view];
[self.pageVC didMoveToParentViewController:self];
Please try the opposite calls you have described:
[self.pageVC.view removeFromSuperview];
[self.pageVC removeFromParentViewController];
I had an issue with the solution I found here and in other posts, because I called dismissViewController in one of the children views of the pageViewController, so I didn't dismiss the pageViewController itself, just the shown children view.
Turns out, I found a quick way to dismiss the pageViewController from one of its subViews by pressing a button: just connect this button to the Exit button in the storyboard to unwind (and provide the unwind method in the presenting vc).
If you want to dismiss the UIPageViewController from a button from within one of the pages, you could add the below code, in the button action. This is similar to the answer given by Alex Peda, the difference being the reference to the pageViewController is through the parentViewController property.
let pvc = self.parentViewController as! UIPageViewController
//remove the page controller content view from the superview.
pvc.view.removeFromSuperview()
//remove the pageviewcontroller from its parent view controller.
pvc.removeFromParentViewController()
Swift 4 / XCode 9:
While all the proposed answers didn't work for me, this simple line did work:
navigationController?.popViewController(animated: true)
Related
I am trying to segue back to another UIViewController after modally presenting a UINavigationController and with it a root ViewController. What I want to happen is for a button to unwind from the root VC of the UINavigationController and return to the initial UIViewController that presented it. I have the unwind method written in the destination VC and button is hooked up to the Exit point of the VC. But when I press the button, nothing happens. Can someone explain what I am doing wrong? Any advice is appreciated.
Storyboard:
Storyboard
Code:
-(IBAction)unwindToClockView:(UIStoryboardSegue*)sender;
{
NSLog(#"Back to Clock View");
}
Additional code can be found here: https://github.com/xinkecf35/TrafficAlarmClock
Okay, I have a solution. It just involves programmatically calling a method trigger by the button that outright dismisses the view controller. The method is below.
-(IBAction)dismissSettings:(id)sender
{
[self dismissViewControllerAnimated:TRUE completion:nil];
}
If anyone can present a solution that uses Storyboards as well, it will be greatly appreciated.
In my image, my first Tabbar is HomeViewController and the second Tabbar is CameraViewController.
What is the proper way to segue to the Tabbarcontroller? You can see the read line, I try to segue this but I
always get the back button in my HomeViewController and It display weird like not showing the navigation name.
In CameraViewController I hide the Tabbar for the use camera button. I try to use segue programmatically like this one.
[self performSegueWithIdentifier:#"sample" sender:sender]
but It doesn't work properly. Is this possible to segue to TabbarController?
You can't call
[self performSegueWithIdentifier:#"sample" sender:sender]
Because you're in TabBarController already. You could implement custom flow. By pressing "Back" button - just show TabBar and change selected tabBarItem for example…
update
used this
[self.tabBarController setSelectedIndex:0];
I create a UINavigationController (as a initial screen) and connect them with my UITableViewController (as a root).
Next, I create another UINavigationController and connect with my UIViewController. Inside my UITableViewController I connect my first cell with UINavigationController (That was connected with my UIViewController) (Segue -> show).
When I run the project my table appears, when I select my first row, my UIViewController appears. Thats great!
When I was in my UIViewController the back bar button doesn't appears, in my case I create a left bar button, that will run a function to dismiss that view and go back to my UITableViewController, for that I use many codes:
-(void)back{
NSLog(#"Called");
[self.parentViewController.navigationController popViewControllerAnimated:YES];
}
-(void)back{
NSLog(#"Called");
[self.navigationController popViewControllerAnimated:YES];
}
-(void)back{
NSLog(#"Called");
[self.navigationController popViewControllerAnimated:YES];
}
But all of they doesn't works and my view don't dismiss, how can I solve this problem?
The problem is that your navigation controller, that you call from your table view cell, has only a single view controller (yours) on its navigation stack. So it cannot pop anything from this stack, else the stack were empty.
What you have to do instead is to dismiss the navigation controller itself.
I think that the solution would be to remove the second navigation controller. Since the TableView is already embedded inside a Navigation Controller, the show segue to the UIViewController must be directly connected to it.
I am using MMDrawerController for making left slide menu in iOS. The problem is that all the view controllers I am using in this project are having slider with them i.e in each UIViewController I can slide to get left menu but I want only with the first view not with all the UIViewController.
How can I stop slider code for the other UIViewController in the project.
you can cancel panning using below method. put that method in viewWillAppear
To allow gesture add this in viewWillAppear
[self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
when you push any view cancel gesture using below code.
[self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
if you don't want side menu for a view controller, call it using segue
example issue code:
assuming you have used this code in the side menu to navigate to other view controllers
switch(item selected) ....
case number:
centerViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"STORYBOARD_ID"];
instead use :
[self performSegueWithIdentifier:#"segue_identifier" sender:nil];
this will navigate to completely new context instead of adding your view controllers to the centerViewController of MMDrawerController
I'm trying to use a popover as an intermediary menu between my main view and a modal view controller. I can successfully present the Modal view controller from the popover by using the following code:
UIStoryboard *storyboardiPad = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
cbwEditControlPanel *editCP = [storyboardiPad instantiateViewControllerWithIdentifier:#"EditCP"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editCP];
[nav setToolbarHidden:NO];
[nav setModalPresentationStyle:UIModalPresentationFullScreen];
[nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:nav animated:YES completion:nil];
self.modalInPopover = NO;
The problem I'm running into is that when the EditCP modal view controller is dismissed, the main view controller never updates. I have a pagecontroller on the main view that should be updated to reflect the number of pages as set in the EditCP modal view controller, but for some reason the modal view controller being called from the popover prevents the main view controller from updating the pagecontroller. I've even tried calling the main view's "View Will Appear" method from the popover or modal view when they are dismissed, but even if the 'viewWillAppear' method is called the pageController will not update!
Any ideas what is preventing the pageController from updating? I even passed a reference to the pagecontroller to the modal view and tried to update it there, but it seems that from the time the popover is presented until it is dismissed, I cannot update the number of pages on the PageController.
Thank you!
So this is an old question but I also came across a similar problem recently when using a popover. My solution was to use an unwind segue to trigger my parent view to perform some action. In my case my parent view contains contact information and the popover contains a list of cites. All I wanted to do was to have the parent view update with the new city once the user selected it from the popover. So in my parent view I create my unwind function as follows:
In the .h:
- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue;
In the .m:
- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue
{
[self updateTableForOffice];
}
In the above .m file is where you would have the logic to do whatever it is you want to in the parent view. To connect this unwind segue go to the child view in the storyboard and control drag from the view icon to the exit icon. You should see a pop up with the name of your unwind segue.
Finally, give that unwind segue a name and then in the child controller in the viewWillDisappear() function call the segue as follows:
- (void)viewWillDisappear:(BOOL)animated
{
[self performSegueWithIdentifier:#"unwind-to-contact-tvc" sender:self];
}
I hope that helps. If someone has a better solution let me know.
Well, I half solved the problem. The only way to get an update function when the popover disappeared was to stop using Storyboards and programmatically present the popover, using the main view as the delegate. I then was able to update correctly inside the popoverControllerDidDismissPopover method.
However, I am still interested in finding a way to update the pageControl when the modal is dismissed, before the popover is dismissed.