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
Related
I am trying to change the preferred content size of a UIPopOverController from inside the childViewController.
Firstly I present PopOverViewController this way
DateViewController *dateView = [[DatePickerViewController alloc] initWithNibName:#"DateViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:dateView];
m_tableCell = (NotesCell *)[m_tableView cellForRowAtIndexPath:indexPath];
popViewController = [[UIPopoverController alloc] initWithContentViewController:navController];
popViewController.backgroundColor = [[AppManager instance].themeManager navigationBarColor];
popViewController.delegate = self;
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect popRect = CGRectMake(m_tableCell.customView.frame.origin.x,
m_tableCell.customView.frame.origin.y,
m_tableCell.customView.frame.size.width,
m_tableCell.customView.frame.size.height);
[popViewController presentPopoverFromRect:popRect
inView:m_tableCell
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
So inside my childViewController i.e (DateViewController), I have button which when toggled will call a function
- (void)toggleButton
{
if(small)
{
self.presentingViewController.presentedViewController.preferredContentSize = CGSizeMake(320,485);
}
else
{
self.presentingViewController.presentedViewController.preferredContentSize = CGSizeMake(320,320);
}
}
This is working fine, but as we know that UIPopOverViewController has arrow, so when I resize the popOverView, the arrow also animates up and down, which I dont want. I cannot show this in image, so please excuse me for that.
Need help
Ranjit.
First of all the code you posted won't work, because in else statement you assign CGSizeMake giving only one value while constructing it.
Secondly you can define in which directions you allow for that arrow by specifying popoverArrowDirection property
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!
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)
So I have a popover with a button in it. When that button is pushed, I want the popover to go away. It seems easy enough, but I can't figure it out for the life of me. The code I use to show the popover is below:
AddCategoryViewController* content = [[AddCategoryViewController alloc] init];
UIPopoverController* aPopover = [[UIPopoverController alloc]
initWithContentViewController:content];
aPopover.delegate = self;
[content release];
// Store the popover in a custom property for later use.
self.addCategoryPopover = aPopover;
[aPopover release];
[addCategoryPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Within the addcategoryviewcontroller, I have:
-(IBAction)saveAddCategory:(id)sender {
if (rootViewController == nil)
rootViewController = [[RootViewController alloc] init];
[rootViewController.addCategoryPopover dismissPopoverAnimated:YES];
[rootViewController dismissPopover];
}
Rootviewcontroller is where the popover is being created from. Unfortunately, neither of those methods work to dismiss it. any help?
You would be seeing a warning at this line.
aPopover.delegate = self;
and if you would execute your code. The app would crash. Instead you need to do it like this.
I have
- (void)viewWillDisappear:(BOOL)anAnimated
{
[self.dPopover dismissPopoverAnimated: NO];
self.dPopover = nil;
[super viewWillDisappear: anAnimated];
}
and don't see why this wouldn't work in your case.
Your if is a bit troubling, so my guess is you aren't talking to the view you think you are. rootViewController.addCategoryPopover is probably nil, because you made a new controller.
I think I answered just a similar question with the solution I used to dismiss a popover with a UIView loaded from a MKMapView.
The use of my solution is basically the same as for any other view loading a popover.
Have a look at:
How to dismissPopoverAnimated on iPad with UIPopoverController in MKMapView (SDK3.2). I hope that solved your problem.
use NSNotificationCenter To DissmissPoperController Fro Father viewControll
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