PopoverView issue - ipad

i am first time using Popoverview, and i have one issue when i am using popover view.
here is the code which i am using it working fine
objManage = [[xyViewController alloc]init];
aPopover = [[UIPopoverController alloc] initWithContentViewController:objManage];
aPopover.delegate = self;
CGSize size = CGSizeMake(768,1004);
[aPopover setPopoverContentSize:size animated:YES];
CGRect rect = importAddress.frame; //CGRectMake(100.0f, 918, 768,900);
[aPopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[objManage release];
So i am sucessfully open view controller in popoverview.
i have one button in xyViewController class, Ok suppose i click on button popover view dismiss, How can i dismiss popoverview in another class.
Thank you,

You want to call the method dismissPopoverAnimated:(BOOL)animated on the popover
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIPopoverController_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009306-CH1-SW9

Related

Change displayed view in a UIPopoverView

So I'm presenting a UIPopoverView like so:
if (self.BStatePopoverViewController == nil) {
RedStatePopoverViewController *settings =
[[RedStatePopoverViewController alloc]
initWithNibName:#"RedState"
bundle:[NSBundle mainBundle]];
UIPopoverController *popover =
[[UIPopoverController alloc] initWithContentViewController:settings];
popover.delegate = self;
self.BStatePopoverViewController = popover;
}
[BStatePopoverViewController setPopoverContentSize:CGSizeMake(320, 445)];
[self.BStatePopoverViewController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Once the view is loaded in the popover, I have a button which I'd like to use to present a new UIViewController within the popover. I tried just presenting it as a modal view but this changes the parent view as opposed to the one in the popover:
PopupDischargeViewController * dischargeview = [[PopupDischargeViewController alloc] initWithNibName:#"PopupDischargeViewController" bundle:nil];
[self presentModalViewController:dischargeview animated:NO];
Any help as to how I do this would be much appreciated.
Thanks!
To change the view controller the popover should display once it's been initialized use UIPopoverController's method – setContentViewController:animated:
You could also add your RedStatePopoverViewController to a UINavigationController and use its methods – pushViewController:animated: and – popViewControllerAnimated: to navigate between view controllers
Hope this helps!

Popover view controller not showing

I have a login view which I want to display in popover. I am doing this from code as below:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[NSString stringWithFormat:#"MainStoryboard_%#", isIPAD ? #"iPad" : #"iPhone"] bundle:NULL];
UIViewController *navCtrl = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navCtrl];
popover = popover;
popover.delegate = self;
popover.popoverBackgroundViewClass = [PopoverBackground class];
self.popover = popover;
[self.popover presentPopoverFromRect:((UIButton *)sender).bounds
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
But the popover never shows. But the weird thing is viewdidload and viewwillappear for loginview are called. And on again clicking on the view calls the popover delegate method didDismissPopover.
Though it works fine when presented from a popover segue.
I do not want to create a segue because login might be called from different locations and I want to keep this code separate.
Has anyone before faced such issue.
Solved it!!
Turned out I was giving the arrow direction as UIPopoverArrowDirectionDown and the rect to show was not proper. Changed the rect to (100, 500, 10, 10), and voila! Everything is perfect.

PopOverWindow over a normal UIButton Click

I am looking for a Methode to use the PopOverWindow with a normal Button.
I found informationen about the Storyboard in combination with the button PopOverView but I dont use a Story board.
So i Need help or a tutorial, of it.
Thanks soo much.
You can use
presentPopoverFromRect:inView:permittedArrowDirections:animated:
and pass it the frame of your button as the first argument.
-(IBAction)yourButton:(UIButton*)sender
{
VC1 *vcObject = [[VC1 alloc]initWithNibName:#"VC1" bundle:nil];
_popOver= [[UIPopoverController alloc] initWithContentViewController:vcObject];
_popOver.delegate = self;
_popOver.popoverContentSize = CGSizeMake(330, 362); // set the size of the popOver you want in your app
[_popOver presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //sender.frame is the button's frame here
}
note: _popOver is an ivar mentioned in the particular VC

Push a View from popOver in ipad

I open a popOver with a view(DetailView) in a view(MapView). it works fine.
But in my detail view has a button(feedback).so i want to push the another view(feedbackform)on btton clicked.
I tried but nothing is Happened.
Can i push the view inside the popover?
My code is as follow:
// MapView.m
detailsView *popUp=[[detailsView alloc] initWithNibName:#"detailsView_ipad" bundle:nil];
popView = [[UIPopoverController alloc]initWithContentViewController:popUp];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(600, 500)];
[popView presentPopoverFromRect:control.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
//Detailview.m
-(IBAction)openFeedbackForm:(id)sender {
fbView = [[deatailsFeedback alloc]
initWithNibName:#"deatailsFeedback_ipad" bundle:nil];
[self.navigationController pushViewController:fbView animated:YES];
}
To achieve this your detailsView should be a Navigation controller with a root controller to the original detailsView.
This way when you pop the navigationController, you can perform push from your detailsView and that would only affect the popOver view
detailsView *popUpView=[[detailsView alloc] initWithNibName:#"detailsView_ipad" bundle:nil];
UINavigationController *popUpNavController = [[UINavigationController alloc] initWithRootViewController:popUpView];
popView = [[UIPopoverController alloc]initWithContentViewController:popUpNavController];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(600, 500)];
[popView presentPopoverFromRect:control.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
//Detailview.m
-(IBAction)openFeedbackForm:(id)sender {
fbView = [[deatailsFeedback alloc]
initWithNibName:#"deatailsFeedback_ipad" bundle:nil];
[self.navigationController pushViewController:fbView animated:YES];
}
If I understand your code correctly, openFeedForm IBAction method is in Detailview.m?
Meaning the first part of the code is in a different class than the one at the bottom?
If so, since Detailview itself is not in a navigationController, it will not push anything to its non-existant navigation controller.
What you want to do is have MapView push the new view in its navigationController.
Side note: since you are setting the delegate of the popUp in MapView as (self) the IBAction method should be defined in MapView
(This is assuming my first statement about understanding your code is correct)

UIPopoverController placement

I'm working on an app that is supposed to be universal, one app for both iPad and iPhone. I would like to keep their interfaces as similar as possible. In the iPhone app I am using a Tab bar controller, and one of those tabs goes to an image picker controller. Obviously I cannot do that in iPad. So I have hijacked control of that button to bring a popupcontroller that has the image picker in it. This all works well enough, except when I bring up the popup, it is not in the correct place. When I rotate the simulator, the popup goes to the correct place, and stays when I rotate back even.
My code is based on the code in this question:
Ipad UIImagePickerController and UIPopoverController error
Why would my popup not be in the correct location?
If your code is based on the question you referenced, it would appear you are using the following code to show the popover:
[popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES]
UIPopoverController:presentPopoverFromBarButtonItem:permittedArrowDirections:animated accepts a UIBarButtonItem* for the sender which your UITabBar does not have. UITabBar uses UITabBarItem which has a base of UIBarItem. UIBarButtonItem also has that base (UIBarItem).
Anyhow... I also needed to show a uipopovercontroller from a tabbaritem, I used the following code:
MyViewController *myVC = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:myVC];
[myVC release];
popover.popoverContentSize = myVC.view.frame.size;
popover.delegate = self;
int tabBarItemWidth = self.tabBar.frame.size.width / [self.tabBar.items count];
int x = tabBarItemWidth * 6;
CGRect rect = CGRectMake(x, 0, tabBarItemWidth, self.tabBar.frame.size.height);
[popover presentPopoverFromRect:rect
inView:self.tabBar
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
Note: your x calculation will be different. The tab bar item selected for me was the 6th one.
Basically
x = tabBarItemWidth * currentTabBarItemIndex;

Resources