简体   繁体   English

Popover视图控制器未显示

[英]Popover view controller not showing

I have a login view which I want to display in popover. 我有一个要在弹出窗口中显示的登录视图。 I am doing this from code as below: 我正在从下面的代码中做到这一点:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[NSString stringWithFormat:@"MainStoryboard_%@", isIPAD ? @"iPad" : @"iPhone"] bundle:NULL];
UIViewController *navCtrl = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navCtrl];
popover = popover;
popover.delegate = self;
popover.popoverBackgroundViewClass = [PopoverBackground class];
self.popover = popover;
[self.popover presentPopoverFromRect:((UIButton *)sender).bounds
                              inView:self.view
            permittedArrowDirections:UIPopoverArrowDirectionDown
                            animated:YES];

But the popover never shows. 但是弹出窗口永远不会显示。 But the weird thing is viewdidload and viewwillappear for loginview are called. 但是奇怪的是viewdidload和viewwillappear出现在loginview上。 And on again clicking on the view calls the popover delegate method didDismissPopover. 然后再次单击视图,调用弹出框委托方法didDismissPopover。

Though it works fine when presented from a popover segue. 从popover segue呈现时,虽然效果很好。

I do not want to create a segue because login might be called from different locations and I want to keep this code separate. 我不想创建segue,因为可能会从不同位置调用登录,并且我想将此代码分开。

Has anyone before faced such issue. 以前有没有人遇到过这样的问题。

Solved it!! 解决了!!

Turned out I was giving the arrow direction as UIPopoverArrowDirectionDown and the rect to show was not proper. 原来,我给的箭头方向是UIPopoverArrowDirectionDown ,显示的矩形不正确。 Changed the rect to (100, 500, 10, 10) , and voila! 将rect更改为(100, 500, 10, 10) 100,500,10,10 (100, 500, 10, 10) ,瞧! Everything is perfect. 一切都很完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM