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
Related
I have requirement like inside the view I need to push some other view controllers. For that I tried to add a one window as subview for that particular view then I have given the desired view controller to root view controller for that window. It is showing correctly but the rootviewcontroller is starting from screen (0, 0) point instead of within the window.
In this picture red color is the view controller and gray one is the view with the origin (0, 100). Below is the code I have tried.
UIWindow *insideWindow = [[UIWindow alloc] initWithFrame: CGRectMake(0, 100, _windowView.frame.size.width, _windowView.frame.size.height)];
insideWindow.backgroundColor = [UIColor yellowColor];
insideWindow.windowLevel = UIWindowLevelNormal;
insideWindow.hidden = NO;
insideWindow.clipsToBounds = YES;
insideWindow.bounds = _windowView.bounds;
_windowView.clipsToBounds = YES;
[_windowView addSubview: insideWindow];
SecondViewController *s = [SecondViewController new];
s.view.bounds = CGRectMake(0, 100, _windowView.frame.size.width, _windowView.frame.size.height);
insideWindow.rootViewController = [SecondViewController new];
[insideWindow makeKeyAndVisible];
It is not a duplicate with how to add multiple UIWindows. Here I can able to add the multiple windows But the problem is inside window the viewcontrollers are not setting properly.
I don't really know what you want to achieve but here we go...
SecondViewController *s = [SecondViewController new];
s.view.bounds = CGRectMake(0, 100, _windowView.frame.size.width, _windowView.frame.size.height);
insideWindow.rootViewController = [SecondViewController new];
You basically create an instance of SecondViewController, then you set the bounds (wrong idea) then you assign as window rootViewController another instance of SecondViewController.
The difference between the frame and bounds of a view: Bounds vs Frame
If you want to go that way, then:
SecondViewController *s = [SecondViewController new];
s.view.frame = CGRectMake(0, 100, _windowView.frame.size.width, _windowView.frame.size.height);
insideWindow.rootViewController = s;
Instead of adding windows to display view controllers why you don't add the "SecondViewController" as child to the controller which has the "gray" view?
SecondViewController *s = [SecondViewController new];
[firstViewController addChildViewController:s];
s.view.frame = grayView.bounds; // or CGRectMake(...)
[grayView addSubview:s.view];
[s didMoveToViewController:firstViewController];
I'm initialising my UIPopoverPresentationController from code:
ChoseOptionsViewController *contentController = [[ChoseOptionsViewController alloc] init];
contentController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *copvc = contentController.popoverPresentationController;
copvc.permittedArrowDirections = UIPopoverArrowDirectionAny;
copvc.sourceView = sender;
copvc.sourceRect = sender.bounds;
contentController.preferredContentSize = CGSizeMake(200, 200);
[self presentViewController:contentController animated:YES completion:nil];
And all I'm getting is an empty 200x200 view, although I've created a ViewController in storyboard, assigned ChoseOptionsViewController class to it and dragged some UI elements.
Tell me please, how can I get my view from storyboard when initialising a popover from code.
Thanks in advance.
When you make a view controller in the storyboard, you should create an instance of it with instantiateViewControllerWithIdentifier:, not alloc init.
ChoseOptionsViewController *contentController = [self.storyboard instantiateViewControllerWithIdentifier:#"Whatever"];
Make sure your controller in the storyboard has its identifier set to the same string you pass to the method.
I would like to create a subview which loads notifications similar to Facebook in its iOS app. Does anyone know how to build that?
Thanks!
Something like that:
http://www.techarp.com/article/Apple/Facebook_Notifications/facebook.jpg
I suggest you to use a UIPopoverController.
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"UIViewControllerNibName" bundle:nil];
viewController.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
navController.contentSizeForViewInPopover = CGSizeMake(400, 200);
viewController.contentSizeForViewInPopover = CGSizeMake(400, 200);
poopover.delegate = self;
CGRect rect = CGRectMake(0, 0, yourWidth, yourHeight);
[popover presentPopoverFromRect:locRect inView:parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:TRUE];
viewController is the UIViewController inside the popover, and there you can add, for example, a UITableView to show notifications. UIPopoverController is responsible of showing the popup view. Of course in presentPopoverFromRect: method you have to pass the frame the popover anchors to, the view in which present the popover, the arrow directions allowed and the animate flag in order to show the popover in an animated manner. Finally, with delegation you can communicate to the class that is allocing the popover (self.delegate = self).
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
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