Domanda

I have a iPad app (XCode 5, iOS 6, ARC and Storyboards), which has a class to display a UIView. From a separate class, I want to display a UIPopover under a certain condition.

I'm having a problem with the last line of code:

//  create a popover for login or registration
UIViewController* popoverContent = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 280, 180)];
popoverView.backgroundColor = [UIColor lightGrayColor];
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 280);  //  was 180

//create a popover controller
popoverController = [[UIPopoverController alloc]   initWithContentViewController:popoverContent];

//  if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
    [popoverController dismissPopoverAnimated:YES];
}

//    [popoverController presentPopoverFromRect:popoverView inView:self
//                     permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

SettingsViewController *svc = [[SettingsViewController alloc]init];
[popoverController presentPopoverFromRect: popoverView inView:svc.view.frame
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

It's telling me:

Sending 'UIView *__strong' to parameter of incompatible type 'CGRect' (aka 'struct CGRect')

How do I fix this? (I've tried different ways of presenting the popover, but none of them work).

È stato utile?

Soluzione

Assuming the popoverView is the section of the svc view you want the popover to present from, your code should read:

[popoverController presentPopoverFromRect:popoverView.frame inView:svc.view
             permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

This will correct that error.

Edit: The reason it's probably not displaying for you is because you seem to be misunderstanding the presentPopoverFromRect method. The frame you indicate in the presentPopoverFromRect method needs to correspond the point of the view you'd like the popover to emerge from. For example, to have the popover present from the top left corner of the view, do something like this:

[popoverController presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:svc.view
             permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top