简体   繁体   中英

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. And on again clicking on the view calls the popover delegate method didDismissPopover.

Though it works fine when presented from a 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.

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. Changed the rect to (100, 500, 10, 10) , and voila! Everything is perfect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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