我有一个iPad应用程序(XCode 5,iOS 6,ARC和Storyboards),它有一个显示UIView的类。从一个单独的类,我想在一定条件下显示UIPopover。
我遇到了最后一行代码的问题:
// 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];
告诉我:
将'UIView * __ strong'发送到不兼容类型'CGRect'(又名'struct CGRect')的参数
我该如何解决这个问题? (我尝试过不同的方式呈现弹出窗口,但没有一种方法可以工作)。
答案 0 :(得分:1)
假设popoverView是svc视图的一部分,你想要弹出窗口,你的代码应该是:
[popoverController presentPopoverFromRect:popoverView.frame inView:svc.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
这将纠正该错误。
编辑:它可能不会为您显示的原因是因为您似乎误解了presentPopoverFromRect方法。您在presentPopoverFromRect方法中指示的框架需要与您想要突出显示的视图的点相对应。例如,要从视图的左上角显示弹出窗口,请执行以下操作:
[popoverController presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:svc.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];