Hide Popover controller - ios

In my project i'm using the WEPopover,
I can able to to call and custom popover with the help of it but, the problem is I can't able to dismiss the popover with a help of button present in the popover.
NOTE:-
I'm calling the popover from UIBarButtonItem
The content of the popover is of a view controller
I'm calling the popover in all the vie'w I'm using it like a help button
I'm calling the popover in all the view's like this
if (self.popoverController)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
else
{
NSString * storyboardName = #"MainStoryboard";
NSString * viewControllerID = #"settings";
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
SettingsViewController * controller = (SettingsViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
self.popoverController = [[WEPopoverController alloc] initWithContentViewController:controller];
[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
and I want to dismiss the popover with a help of button which is present in the view controller which has been exposed as a popover.
Need some help as i'm new to IOS developing.

Mmm, I guess you have two options.
Implement a delegate in your Settings ViewController, to indicate when the help button is pressed, and make parentViewController dismiss the popover
Setup a new property in your SettingsViewController to assign the popover
#property (nonatomic, weak) WEPopoverController *popoverController;

Related

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.

Displaying modal views programmatically

I want to be able to show a viewController when a button is pressed.
I don't want to use a navigation controller anymore, is there a way to display it using a modal?
Here is how I am currently showing the viewController:
- (void) editButtonDidClicked: (UIButton *) button {
EditViewController *viewController = [EditViewController getInstanceWithTag:button.tag];
[self.navigationController pushViewController:viewController animated:YES];
}
You can try below code
I assume that you are using storyboard.
UIStoryboard *board = [UIStoryboard storyboardWithName:#"name" bundle:nil];
viewController *controller = [board instantiateViewControllerWithIdentifier:#"Identifier"]; // Identifier is define in storyboard
[self presentViewController:controller animated:YES completion:nil];
Please check out this link if you are still facing the problem.
Hope this helps you.

pushViewController not working after back

For my code structure:
On AppDelegate, I declared 4 UINavigationController with their own root UIViewController for my UITabBar.
I created one custom UIViewController as template, in where my other UIViewControllers are sub-class.
On my template:
I have my rightBarButtonItem to show current user profile.
// public method added on template
- (void) goToProfile {
NSLog(#"going through...");
ProfileViewController *ctrl = [[ProfileViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
}
For my leftBarButtonItem:
- (void) goBack {
[self.navigationController popViewControllerAnimated:YES];
}
First click on the rightBarButtonItem, works fine. If I click the leftBarButtonItem to go back then re-click the rightBarButtonItem, it won't work anymore.
In addition, I have a button on one of my UIViewController that is calling the public method goToProfile. And that works fine.
I got help from my co-worker. The approach is something similar to #Vidhyanand900 answer. I hope this will help others in the future.
tabbarSelectedIndex = 1; // profile tab index
ProfileViewController *ctrl = [[ProfileViewController alloc] init];
UINavigationController *navController = [_appDelegate.mainTabBarController.viewControllers objectAtIndex:tabbarSelectedIndex];
[navController pushViewController:ctrl animated:YES];
self.mainTabBarController.selectedIndex = tabbarSelectedIndex;
If you are pushing or popping with UINavigation controllers of UITabBar
Else show UINavigation Controllers inside UITab Bar..i.e; Is Profile View controller is part of UITab bar or not..
Then you need to change the index of tab bar as below
self.tabBarController.selectedIndex=0;//if profile is first tab
ProfileViewController *ctrl = [[ProfileViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
Hope it helps you...

UIPopovercontroller doesn't show anything on iPad Simulator(xCode6.1)

I am trying to show the UIPopovercontroller that involves UIPickerView when I click a button on iPad. I can see the UIPopovercontroller but I can't see the UIPickerView in UIpopovercontroller
I've already made a ViewController which has the UIPickerViewer in storyboard for UIPopovercontroller.
So what am I missing now?
Here are the code I am using.
#property (nonatomic, strong) UIPopoverController *userDataPopover;
- (IBAction)setTime:(id)sender {
DatePickerViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"datePickerView"];
viewController.delegate = self;
self.userDataPopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
self.userDataPopover.popoverContentSize = CGSizeMake(400, 400);
[self.userDataPopover presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES]; }
Try these
0 - Check height of date picker.
1 - Check constraints if you have any.
2 - Can you try to add DatePicker directly to popover controller
when I use following code, it works well.
DatePickerViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"datePickerView"];
[self presentViewController:viewController animated:YES completion:nil]
But there is a problem when I use Popovercontroller.

How to connect UIPopoverViewController in StoryBoard

I am trying to implement UIPopoverController. I have seen some sample code but still confused on how to connect the popover view controller to storyboard. Help please.
if (!patientPopover) {
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil];
MyViewController * addPacientController = [storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
UINavigationController * myNavController = [[UINavigationController alloc] initWithRootViewController:MyViewController];
patientPopover = [[UIPopoverController alloc] initWithContentViewController:myNavController];
patientPopover.delegate = self; // optional
}
[patientPopover presentPopoverFromBarButtonItem:yourInstanceBarButtonItemOrMethodArgumentAttachedToTheBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
It's good to have your popover in an instance variable so that you avoid allocating it each time you press the button. I am using here presenting the popover from a UIBarButtonItem, but you can also present it from any view, like :
[patientPopover presentPopoverFromRect:yourView.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You don't need to visually see the actual popover in the storyboard or nib file, because it is only a container. You just need to see what goes inside it, and that is the view controller, and obviously, you can do that.

Resources