how to dissmiss a popover on button click and how to change the size - objective-c

I am using UIPopover to display videos using UIImagePickerController.In this I have to dismiss my popover when use is clicked.Can anyone please help me to do this?
Also I want to change the size of the popover.Now I am using the below code to chane the size.But it is not working.Width is not getting changed.
[popOver1 setPopoverContentSize:CGSizeMake(1000.0 , 500.0) animated:YES];
Please give me a solution for these two problems..

For dismissing popover controller you can use below code in button action method.
[popoverController dismissPopoverAnimated:YES];
For changing the width you can change the frame of the popover controller not contentSize.
popoverRect = CGRectMake(x, y, width,height);
i found you are trying like this
[popOver1 setPopoverContentSize:CGSizeMake(1000.0 , 500.0) animated:YES];
//it means in increases the contentSize not the width

Related

UIView in UITableView disappear when becomes firstResponder

In storyboard I have a UITableViewController-->UITableView-->UITableViewSecion--> with static cells
in the same UITableView I also have a UIView that holds a background image and UITextView.
A click on a button shows the UIView and set it's frame, which appears OK, but as soon as I click on the UITextView or make it firstResponder programmatically the keyboard appears and the view disappears
the code when clicking the button
self.myView.frame = CGRectMake(0, self.tableView.contentOffset.y+100, self.tableView.frame.size.width, self.tableView.frame.size.height-100);
self.myView.hidden = NO;
how can I fix this?
Can you copy paste us the code where you add the view to the tableview? Are you doing it with constraints or with frames?
The issue you are having is probably due to the fact the UITableViewControllers automatically shrink the contentSize of the UITableView they hold when the keyboard shows. If you add a UIView to your tableView with addSubview: programmatically, you might need to add a flexible bottom resize mask to make sure when the contentSize shrinks in height, your view stays attached to the top and not the bottom.
Try this on viewDidLoad:
[theViewYouAddedToTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];

iOS 8 - Modal in Popover

I have a popover with TabBarController in it. In one tab there is a TableViewController with a list of names. And there is a plus button, that has a modal segue to AddCharacterVC for adding new names.
In iOS 7 I do it like this:
AddCharacterViewController *acvc = (AddCharacterViewController *)segue.destinationViewController;
acvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
acvc.modalPresentationStyle = UIModalPresentationCurrentContext;// so it does not take full screen in popover
And in AddCharacterVC I set content size like this:
- (void)viewWillAppear:(BOOL)animated {
CGSize size = CGSizeMake(320, 480); // size of view in popover
if (IDIOM == IPAD && [self respondsToSelector:#selector(preferredContentSize)]){
self.preferredContentSize = size;
}
And it works perfectly.
However, in iOS 8 modal view does not cover the whole popover, leaving TabBar visible. The user can tap on it or not, anyway modal view won't unwind properly.
I've tried:
setting acvc.modalPresentationStyle to UIModalPresentationOverCurrentContext
tried to set TabBar hidden
checked in storyboard that edges of TableVC extend under Bottom Bar and Bottom Bar in Modal View (AddCharacterVC) is set to none
All with no results.
Now the only thing I can think of is to try making modalPresentationStyleCustom and use UIPresentationController (I'm trying to do it now, but I haven't done it before). Am I missing something? Could there be other way to do it? Sorry, I cannot post images here yet. Many thanks in advance!
Ok, so I've set the modalPresentationStile to UIModalPresentationCustom, and used UIPresentationController - I've just copied code from WWDC-14's LookInside project and modified it a bit.
I'm not sure if it was the best solution, but it worked in my case.

iPad: Popover windows got resized iOS

CGRect rect = CGRectMake(0, 0, 1050, 900);
[wineAdminPopup presentPopoverFromRect:rect inView:master.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Hi I put the above code to make a popup in a tableview. However it doesn't popup in the whole screen. If I want to center it in the iPad screen with no arrow or arrow in the center. How can i do it. Thanks in advance.
The rect parameter in presentPopoverFromRect:... specifies the rectangle at which to anchor the popover, not the size of the presented popover. That would be specified by setting contentSizeForViewInPopover on the popover's content view controller.
If you don't want the arrows and don't need the specific behavior of popovers, then you could
present your view controller modally:
controller.modalPresentationStyle = UIModalPresentationFullScreen; // or UIModalPresentationFormSheet
[self.navigationController presentModalViewController:controller animated:YES];
presentModalViewController is deprecated in iOS 6 and above. Use presentViewController:yourViewController animated:YES completion:nil (parameters animated and completion can be set depending on your requirements). Also if you want to resize yourViewController you need to change self.view.frame and next time your view controller will be of that size.

UIPopover Not Showing View Inside

I'm using a popover that should simply show a UIView inside. But although the popup shows up, it contains only an empty view (that is colored in some kind of dark blue).
The UIViewController is use is the "PreferencesController" in there.
My Code to open the popup is the following:
- (IBAction)showPopup:(id)sender {
if (_preferencesController == nil) {
self.preferencesController = [[PreferencesController alloc]init];
self.preferencesControllerPopover = [[UIPopoverController alloc]
initWithContentViewController:_preferencesController];
}
[self.preferencesControllerPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:0 animated:YES];
}
Besides that I only have the "preferencesController" that doesn't include any special methods besides the viewDidLoad with "self.contentSizeForViewInPopover = CGSizeMake(800.0, 800.0);"
This is what I get:
Any ideas why it isn't working properly?
Possible Problem
800.0 width is too large for a Popover to handle.
In the documentation for UIViewController:
(Discussing contentSizeForViewInPopover)
This property contains the desired size for the view controller when it is displayed in a popover. By default, the width is set to 320 points and the height is set to 1100 points. You can change these values as needed.
The recommended width for popovers is 320 points. If needed, you can return a width value as large as 600 points, but doing so is not recommended.
Possible Solution
Try presenting your UIViewController modally by calling presentModalViewController:animated: from the UIViewController you want the modal view controller to animate on top of.
I think this code makes the issue:
[self.preferencesControllerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:0 animated:YES];
Because sender is of type id, so you need to cast it, Like:
UIBarButtonItem *but = (UIBarButtonItem *)sender;
[self.preferencesControllerPopover presentPopoverFromBarButtonItem:but permittedArrowDirections:0 animated:YES];
Hope it'll solve the issue.

Removing UIPopOver permittedArrowDirections

I have a UIPopOverController and this is my code:
[myPopOver presentPopoverFromRect:CGRectMake(20,5, 325, 600) inView:self.view permittedArrowDirections:**UIPopoverArrowDirectionLeft** animated:YES];
However I need no direction arrows.can any one tell me how can I do it. How can I remove the arrow from it?
Now myPopOver displaying 4 photolibrary images on a Row.can any one tell me how can arrange or display only two images on a row in myPopOver controller.
And also it dismissing when I click on ay place.I don't want to dismiss it.is the any property to avoid the dismiss of uipopover?
I used the code
imagePopOver = [[UIPopoverController alloc] initWithContentViewController:self.plc.imagePickerController];
imagePopOver.popoverContentSize = CGSizeMake(150,300);
You can remove arrow from UIPopover with the help of below code.
[popOverController presentPopoverFromRect:CGRectMake(200, 300, 335, 332) inView:self.view permittedArrowDirections:NO animated:YES];
in swift
let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .ActionSheet)
alertController.popoverPresentationController?.permittedArrowDirections = []
You cannot have no direction arrows with a UIPopover. If you just want a view that appears than you will need to make your own custom UIView and hide it or turn the alpha to 0 and fade it in when you need it. As far as view layout goes you can set the frame property of your image views that you are showing to control where they are placed.
My solution in SWIFT:
popover!.permittedArrowDirections = nil