UIPopoverController presentPopoverFromBarButtonItem allows to press navigation button twice - ios

I am using this code below for presenting UIPopoverController view:
[popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
So everything works good, but I am still able to press UIBarButtonItem which a sender in the code above.
So do I need to disable this button when the popover is shown by my self or there is some another solution?

Use this method instead, where toolbar is the view containing the sender:
[popover presentPopoverFromRect:sender.frame inView:toolbar permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Related

xcode 7.3.1 my storyboard segues to popover are mis-aligned. Objective c

If I simply drag a popover segue from a button, the arrow aligns to the top left of the button, instead of the center.
Anyone have any ideas?
I solve this problems using PopoverController, use UIPopoverControllerDelegate
myPopover = [[UIPopoverController alloc] initWithContentViewController:destinationViewController];
myPopover.delegate = self;
[myPopover presentPopoverFromRect:((UIView *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

UIReferenceLibraryViewController in UIPopovercontroller

I was recommended to use a UIPopovercontroller in order to display my UIReferenceLIbraryViewController so that the dictionary does not take up the entire screen when I click my UIButton "search"
What I have is a UITextField that takes in the string/word, a button that will search it and pull up the UIReferenceLibraryViewController.
I'm having problems using a popovercontroller to do this. When I tried it, the button doesn't respond. Any tips/help??
edit:
UIReferenceLibraryViewController in a popover
It was originally
if([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:searchTerm])
{
UIReferenceLibraryViewController *referenceLibraryVC = [[UIReferenceLibraryViewController alloc] initWithTerm:searchTerm];
[self presentModalViewController:referenceLibraryVC animated:YES];
}
which makes it take up the entire ipad screen
Does UIReferenceLIbraryViewController have initWithFrame? that solution didn't seem to work for me either
Thanks to Leo Nathan's help, it works now.
self.masterPopOverController = [[UIPopoverController alloc] initWithContentViewController:referenceLibraryVC];
[self.masterPopOverController presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I didn't connect it correctly in the XIB file and it wasn't implemented in the correct place in the IBAction for ButtonPress

UIBarButtonItem registers click event next to button, not on button

I got the popup, used at 2 locations within my app, one time in a navigation controller one time without navigation controller,
i got one button in a uitoolbar (select button) but this button has it's own life for some reason
The one in the navigation controller is working perfectly.
But the one called without navigation controller resizes this popup so i resized it back in the code like
- (void)showModal:(UIViewController *)controller
{
[controller setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:controller animated:NO completion:nil]; //Method used without navigationcontroller
[controller.view setBounds:CGRectMake(0,0, 600, 748)]; //resize => button doesn't work at all
//[controller.view setFrame:CGRectMake(0, 0, 600, 748)]; //resize => button only registers click event left from the actual button
//[[NSNotificationCenter defaultCenter] postNotificationName:#"show modal" object:controller]; // Method used within navigationcontroller
}
I've been looking all over google but i can't find anything on this problem.
Hope I have more luck here.
Probably the easy way to sort this problem out is to put it in a UINavigationController and use that to pop up. Then you don't have to use a UIToolBar.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewControllerToPopUp];
[viewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentModalViewController:navController animated:YES];
This way the viewController you are presenting stays simple and you already know the button works when it is a navigation controller :)

Dismissing and Opening a UIPopOver with one UIToolBarItem Button?

I was wondering how I could use 1 button on my ToolBar to open and dismiss my UIPopOver. If I keep tapping the button right now, another PopOver overlaps the previous one. I want ONE button to be able to dismiss and open my PopOver. I tap once, it opens. I tap the button again, it dismisses. Please tell me how. Thanks
In your button tap action event:
if (myPopover.popoverVisible) //self.myPopover if using property
{
[myPopover dismissPopoverAnimated:YES];
return;
}
//continue code here to create/present your MyPopover…
Quick way to do it is to define a UIPopOverController property in your presenting view controller and use this property to instantiate your popover (and accompanying content view controller).
In your presenting view controller you'll need something like:
UIViewController *aViewController = [[UIViewController alloc]init];
self.popOverController = [[UIPopoverController alloc] initWithContentViewController:aViewController];
Then in your button's action to toggle the popOver it should do something like:
if(self.popOverController.popoverVisible) {
[self.popOverController dismissPopoverAnimated:YES];
} else { //Display the popover }
Hope that help

UIPickerView issue in iPad

I am repeating this question again because i couldn't find any solution.
My problem i have an XIB where i have labels and a UIPickerView.I am trying to use this XIB inside a UIPopOverController in iPad.But the view is not rendered properly.Actually this is the view which i am adding it to the popover window.
This is the code which i am using
MyPricePickerViewController *priceviewobj=[[MyPricePickerViewController alloc]init];
UINavigationController *navigationcontroller=[[UINavigationController
alloc]initWithRootViewController:priceviewobj];
popover = [[UIPopoverController
alloc]initWithContentViewController:navigationcontroller];
[popover setPopoverContentSize:CGSizeMake(290,410) animated:YES];
[self.popover presentPopoverFromRect:CGRectMake(10,212,20,30) inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
I display other XIBs which dont have a UIPicker view and they are displayed properly.When i run the application the popover is rendered as follows
Please anybody suggest me a possible solution to this problem.Thanks in advance

Resources