pushing a view controller from presented popup view controller - ios

I am presenting a view controller as a popup and in the popup view controller i have a button , onclick of that button i am trying to push a view controller but nothing happens on click.How to do this?
Presnting the view controller as a popup
- (IBAction)sendOTPAction:(id)sender {
HMResetPasswordViewController *resetPassword = [self.storyboard instantiateViewControllerWithIdentifier:#"HMResetPasswordViewController"];
// configure the Popover presentation controller
resetPassword.modalPresentationStyle = UIModalPresentationPopover;
resetPassword.preferredContentSize = CGSizeMake(self.view.frame.size.width-10, 375);
resetPassword.popoverPresentationController.delegate = self;
resetPassword.popoverPresentationController.permittedArrowDirections = 0;
resetPassword.popoverPresentationController.sourceView = self.view;
resetPassword.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0);
[self presentViewController:resetPassword animated:YES completion:nil];
}
Trying to push the view controller from popup view controloer
- (IBAction)resetButtonAction:(id)sender {
HMLoginViewController *HMLoginViewController= [self.storyboard instantiateViewControllerWithIdentifier:#"HMLoginViewController"];
[self.navigationController pushViewController:HMLoginViewController animated:YES];
}

After presenting, if you want to use navigation stack then you have to create new navigation controller :
- (IBAction)resetButtonAction:(id)sender {
HMLoginViewController *HMLoginViewController= [self.storyboard instantiateViewControllerWithIdentifier:#"HMLoginViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:HMLoginViewController];
[self presentViewController:nc animated:YES];
}
After HMLoginViewController, now you can push to other UIViewController

Related

How to push to view controller form presented xib

I have xib of passcode and after I tap on login button there will be web service that will call and after success response, I have to present xib of passcode.
When I complete that portion I have to push to another view controller from presented xib.
Here is my code:
[self dismissViewControllerAnimated:NO completion:^{
if ([_delegate respondsToSelector:#selector(unlockWasSuccessfulLockScreenViewController:pincode:)]) {
[_delegate unlockWasSuccessfulLockScreenViewController:self pincode:pincode];
PassCodeVC *sgn = [self.storyboard instantiateViewControllerWithIdentifier:#"PassCodeVC"];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:sgn];
[nav pushViewController:sgn animated:YES];
}
}];
and I have presented xib like this:
JKLLockScreenViewController * viewController = [[JKLLockScreenViewController alloc] initWithNibName:NSStringFromClass([JKLLockScreenViewController class]) bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
[viewController setLockScreenMode:LockScreenModeNew]; // enum { LockScreenModeNormal, LockScreenModeNew, LockScreenModeChange }
[viewController setDelegate:self];
[viewController setDataSource:self];
[viewController setTintColor:[UIColor colorWithRed:53.0 / 255.0 green:115.0 / 255.0 blue:157.0 /255.0 alpha:1]];
[self presentViewController:nav animated:YES completion:nil];
If you wish to use current navigation then Just simple pass new controller using current navigation controller.
PassCodeVC *sgn = [self.storyboard instantiateViewControllerWithIdentifier:#"PassCodeVC"];
[self.navigationController pushViewController:childViewController animated:YES];
You may need to set the Storyboard ID of the View Controller you are trying to load. This is located in the inspector, just below where you assign a custom class to your view controller.see this image

iOS: SWRevealViewController revealToggle is been call but doesn't do nothing

I'm trying to implement SWRevealViewController on this scenario:
From my main viewController:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SWRevealViewController *SWR = [storyboard instantiateViewControllerWithIdentifier:#"SWRevealViewController"];
[self presentViewController:SWR animated:YES completion:nil];
}
From my green view controller:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
self.reveal = [[SWRevealViewController alloc] init];
self.reveal.delegate = self;
self.menu.target = self;
self.menu.action = #selector(revealToggleAction:);
[self.view addGestureRecognizer:self.reveal.panGestureRecognizer];
NSLog(#"viewDidLoad");
}
-(void)revealToggleAction:(id)sender
{
[self.reveal revealToggle:self];
}
The revealToggle action is been call but doesn't do anything. It doesn't load the rear view controller. Any of you knows this happening or what I'm doing wrong?
Assuming that you are showing the side bar menu from right side.
First Embed your first view controller to navigation controller, then in your first view controller viewdidload() or viewDidAppear method add below mentioned code i.e.
//this is your side menu view controller.
UIViewController *sideMenuController =
[self.storyboard instantiateViewControllerWithIdentifier:#"YourSideMenuIdentifier"];
//this is the navigation controller embed to your green view controller.
UINavigationController *nc1 =
(UINavigationController *)[self.storyboard instantiateViewControllerWithIdentifier:#"YourNavigationControllerIdentifier"];
//This is your reveal view Controller.
SWRevealViewController *revealViewController =
[[SWRevealViewController alloc]initWithRightViewController:sideMenuController frontViewController:nc1];
[self.navigationController pushViewController:revealViewController animated:YES];
[self.navigationController setNavigationBarHidden:YES];
This will navigate to Controller i.e Green View Controller.
then in your green view controller viewdidload() or viewDidAppear method add below mentioned code i.e.
//GreenViewController.h file
#interface GreenViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sideBarItem;
#end
//Your GreenViewController.m file
_sideBarItem.target = self.revealViewController;
_sideBarItem.action = #selector(rightRevealToggle:);
SWRevealViewController *revealController = [self revealViewController];
[self.view addGestureRecognizer:revealController.panGestureRecognizer];
Note: For more details, check below mentioned link
http://www.appcoda.com/ios-programming-sidebar-navigation-menu/
You need set SWRevealViewController is the initial view controller.
You are creating a new instance of SWRevealViewController.
I think if you set the self.reveal to self.revealViewController it will work.

UIPopoverPresentationController showing full screen modal popup always

I am trying to show a view controller as UIPopoverPresentationController below the button or in center of window. But it is always showing as full window modal popup.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MySecondViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"Pop"];
// present the controller
// on iPad, this will be a Popover
// on iPhone, this will be an action sheet
controller.modalPresentationStyle = UINavigationControllerOperationPop;
[self presentViewController:controller animated:YES completion:nil];
controller.preferredContentSize = CGSizeMake(280, 230);
// configure the Popover presentation controller
UIPopoverPresentationController *popController = [controller popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionUp;
popController.delegate = self;
// in case we don't have a bar button as reference
popController.sourceView = self.showPop;
popController.sourceRect = CGRectMake(384, -120, 280, 230);
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
Try this code it is working
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SecondViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"pop"];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.preferredContentSize = CGSizeMake(280, 230);
// configure the Popover presentation controller
controller.popoverPresentationController.delegate = self;
controller.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
// in case we don't have a bar button as reference
controller.popoverPresentationController.sourceView = self.view;
controller.popoverPresentationController.sourceRect = CGRectMake(384, -120, 280, 230);
// controller.presentationController.delegate = self;
[self presentViewController:controller animated:YES completion:nil];
I have posted another question for the same question and i have resolved my issue. Here is the link of question:
UIPopoverPresentationController is showing full screen modal on iPhone
In ViewController.h Firstly make a property of UIPopoverPresenatationController.
#property(nonatomic,retain)UIPopoverPresentationController *dateTimePopover8;
Then to show PopOverPresentationcontroller
UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:dateVC];
/*Here dateVC is controller you want to show in popover*/
dateVC.preferredContentSize = CGSizeMake(280,200);
destNav.modalPresentationStyle = UIModalPresentationPopover;
_dateTimePopover8 = destNav.popoverPresentationController;
_dateTimePopover8.delegate = self;
_dateTimePopover8.sourceView = self.view;
_dateTimePopover8.sourceRect = [sender frame];
destNav.modalPresentationStyle = UIModalPresentationPopover;
destNav.navigationBarHidden = YES;
[self presentViewController:destNav animated:YES completion:nil];
You must have noticed that we are presenting View Controller instead of presenting popOver.So we have to hide this in new way also.It hides automatically when we click on screen.
-(void)hideIOS8PopOver
{
[self dismissViewControllerAnimated:YES completion:nil];
}
We have to implement the delegate of UIPopoverPresenatationController in implementation file.Write below delegate method in implementation file.
- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller {
return UIModalPresentationNone;
}
In Storyboard this is very easy. Just control drag from the control that will trigger the action (say a UIBarButton or a normal button) to the storyboard view controller (if root view of Navigation controller, drag to the navigation controller).
Select the segue and change the Kind in the attribute inspector to "Present Modally", presentation: Form sheet (if you want it to show at the centre), select the transition type you want (default is cool).
As #Lukas1 mentioned above, you should conform UIPopoverPresentationControllerDelegate and implement adaptivePresentationStyle method (which is actually defined in UIAdaptivePresentationControllerDelegate protocol, UIPopoverPresentationControllerDelegate parent class) and return .none
And here's implementation in Swift5 :
extension ViewController: UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
}

Issue with definesPresentationContext / UIModalPresentationCurrentContext - Current context view controller gets lost

This only accours if you are presenting in a view controller that is managed by a navigation controller.
The reproduction steps are:
1 - Present a view controller using UIModalPresentationCurrentContext
self.definesPresentationContext = YES;
ViewController* viewController = [[ViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentOnViewController presentViewController:viewController animated:YES completion:nil];
2 - Present a view controller over the top using the default full screen presentation style
ViewController* viewController = [[ViewController alloc] init];
[self presentViewController:viewController animated:YES completion:nil];
3 - Dismiss the top presented view controller (the full screen one)
[self dismissViewControllerAnimated:YES completion:nil];
Now the problem is the 2nd view controller (presented using UIModalPresentationCurrentContext) disappears. Also it is impossible to present another view controller using UIModalPresentationCurrentContext, because the system thinks its still there.
I believe the issue is a bug in the framework. As mentioned it only occurs when the presenting in a view controller managed by a navigation controller. There is a nasty work around which uses the containment API. It creates a dummy view controller which views are presented from. The steps are:
1 - When presenting a view in context who's parent is a navigation controller, use a dummy view controller:
- (void)presentInContext
{
UIViewController* presentOnViewController = self;
if ([self.parentViewController isKindOfClass:[UINavigationController class]])
{
// Work around - Create an invisible view controller
presentOnViewController = [[DummyViewController alloc] init];
presentOnViewController.view.frame = self.view.frame;
// Containment API
[self addChildViewController:presentOnViewController];
[self.view addSubview:presentOnViewController.view];
[presentOnViewController didMoveToParentViewController:self];
presentOnViewController.definesPresentationContext = YES;
}
ViewController* viewController = [[ViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentOnViewController presentViewController:viewController animated:YES completion:nil];
}
2 - When dismissing the view controller tidy up
- (void)dismissSelf
{
__weak UIViewController* presentingViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^{
// Remove the dummy view controller
if ([presentingViewController isKindOfClass:[DummyViewController class]])
{
[presentingViewController willMoveToParentViewController:nil];
[presentingViewController.view removeFromSuperview];
[presentingViewController removeFromParentViewController];
}
}];
}
Thats it... The fix is dirty, but does the trick with no visual flicker.

IOS: start navigation controller form a secondary view

In my app I have a first view controller and I open my secondview controller in this way:
[self presentModalViewController:puntiVendita animated:YES];
but when I'm in secondViewController I have a tableView and I want to begin a navigation controller...what can I do to start a navigation controller from seconviewcontroller via code?
thanks
Just create a navigation controller:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:puntiVendita];
[self presentViewController:navigationController animated:YES completion:nil];

Resources