UIPopover Not Showing View Inside - objective-c

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.

Related

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

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

UIButton inside UIView doesn't respond to touch events

I've put a UIButton inside a custom UIView and the button is not receiving any touch events (it doesn't get into the highlighted state, so my problem is not about being unable to wire up a touch inside up handler). I've tried both putting it into the XIB in Interface Builder, and also tried programatically adding the UIButton into the UIView seperately, both ended with no luck. All my views are inside a UIScrollView, so I first though UIScrollView may be blocking them, so I've also added a button programatically exactly the same way I add my custom view into UIScrollView, and the button worked, elimination the possibility of UIScrollView could be the cause. My View's hiearchy is like this:
The button is over the image view, and the front layer isn't occupying my button completely, so there's no reason for me not be physically interacting with the button. At my custom view's code side, I'm creating my view as such:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIView *sub = [[[NSBundle mainBundle] loadNibNamed:#"ProfileView" owner:self options:nil] objectAtIndex:0];
[self addSubview:sub];
[sub setUserInteractionEnabled:YES];
[self setUserInteractionEnabled:YES];
CALayer *layer = sub.layer;
layer.masksToBounds = YES;
layer.borderWidth = 5.0;
layer.borderColor = [UIColor whiteColor].CGColor;
layer.cornerRadius = 30.0;
/*layer.shadowOffset = CGSizeZero;
layer.shadowRadius = 20.0;
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowOpacity = 0.8;
*/
}
return self;
}
I've tried all combinations of setUserInteractionsEnabled, and had no luck. (Yes, also set them to checked in Interface Builder too). I've also read in another question with a similar problem that I should try overriding 'canBecomeFirstResponder' to return 'YES' and I've also done that too. But the problem persists, I can't click the button. I've not given any special properties, settings to the button, it's just a regular one. My other objects in the view (labels below, image view behind the button etc.) are working properly without problems. What could be possibly wrong here?
Thanks,
Can.
UPDATE: Here is a quick reproduction of the problem: https://dl.dropbox.com/u/79632924/Test.zip
Try to run and click the button.
Looking at the test project, I believe your problem in the way you create TestView, you do not specify the frame for it, so basically the parent view is 0 size, and the subviews you see from XIB extending out of the parent view and thus do not get anything in responder chain.
You should either specify the frame when creating TestView, or adjust the frame after loading XIB file.
I have had this problem as well. The cause for me was that the UIButton superview frame was of height 0, so I believe that even though a touch was happening, it was not being passed down to the button.
After making sure that the button's superview took a larger rectangle as a frame the button actions worked.
The root cause for this problem on my side was a faulty auto layout implementation (I forgot to set the height constraint for the button's superview).
I've found the solution. I was initializing my custom view as:
MyView *view = [[MyView alloc] init];
I've initialized it instead with a frame of my view's size, and it started responding to events:
CGRect rect = CGRectMake(0,0,width,height);
MyView *view = [[MyView alloc] initWithFrame:rect];
Storyboard Solution
Just for anyone wanting a solution to this when using storyboards and constraints.
Add a constraint between the superview (containing the button) and the UIButton with an equal heights constraint.
In my case, I had selected embed UIButton in a UIView with no inset on the storyboard. Adding the additional height constraint between the UIButton and the superview allowed the UIButton to respond to touches.
You can confirm the issue by starting the View Debugger and visually confirm that the superview of the UIButton is not selectable.
(Xcode 11, *- Should also work in earlier versions)

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.

How to add multiple Views to UIScrollView

I have a ScrollView (contentScrollView) which should later contain 20 pages with a UIViewController for each page.
Now this is what I get when adding the UIViewControllers view to the contentScrollView (the Button in the upper right corner is from the MainViewController so it doesn't affect the problem)
and I got this code in my MainViewController class where my contentScrollView is in:
Slide1ViewController*test = [[Slide1ViewController alloc] init];
test.view.frame = CGRectMake(0, 0, 1024, 768);
[self.contentScrollView addSubview:[test view]];
when I add a background like this right after setting the frame:
test.view.backgroundColor = [UIColor blackColor];
then I get the black background without that Bar on the top but the Label which is in the Slide1ViewController.xib won't appear.
Hope someone can help me.
If you really need 20 pages beaing each one a view controller you should use a uinavigationcontroller and if you really wanna have a scroll view, use a uitableview and make each cell the view of one of your uiviewcontroller because that way the each view will be loaded when needed, whereas in a scroll view you might get too much contend loaded at the same time.
I'm sorry i didn't realize UINavigationController was still selected so that i created the class while believing it's a UIViewController

How to make detail view scrollable in master detail app

I have only been working in iOS for a few months but I have been banging my head against the wall for hours and hours for something that seems like it should be pretty straightforward. I used the master detail template in Xcode for an iPad app. I want the detail portion to be scrollable to show content below what is visible in the frame, in either orientation. I have tried numerous combinations of adding scrollviews in the DetailViewController in viewWillAppear, viewDidLoad, loadView...and the best I can come up with is what looks like a scrollable view on the top layer as it does show scroll bars and shows me that I did the scrollView.contentSize correctly as I can pan around, but the actual view with the fields and stuff doesn't move and the fields are unable to be edited. Here is my viewDidAppear as it stands at the moment. As you can see in the NSLogs I am trying to understand the view stack. If I uncomment the line before the logs, I lose the scroll bars altogether.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
scrollView.contentSize = CGSizeMake(2048, 2048);
UIView *parentView = [[UIView alloc] init];
parentView = [[self view] superview];
[[parentView superview] addSubview:scrollView];
//[scrollView addSubview:[self view]];
NSLog(#"%#", [parentView superview]);
NSLog(#"%#", parentView);
NSLog(#"%#", [super view]);
NSLog(#"%#", [self view]);
[scrollView setDelegate:self];
}
I would sincerely appreciate any guidance or tips on how to properly implement UIScrollView for this scenario.
You should add the UIScrollView in IB. Be sure to move all of your existing views and controls to be subviews of the scroll view. And you'll have to link the scroll view to an IBOutlet so you can set the content size in your view controller.
Instead of trying to wrap a uiscrollview around your main view's superview (which you have incorrectly tried to take ownership of (it should be NULL anyways)), why not herd your UI elements into a full-sized subview and wrap the scrollview around that? It would be much much easier.
Your hierarchy would look like this:
Self.view -> ScrollView (with contentSize set) -> UIView containing elements that need to be scrolled -> various UI elements