UIPopViewController not working

后端 未结 3 1480
感情败类
感情败类 2021-02-11 02:43

I have an xib file with a .h and .m linked. In the xib there is a UIView with a textView. What I would like to do with that view is open it as a UIPopViewController when you cli

相关标签:
3条回答
  • 2021-02-11 02:49

    You can use UIPopoverController only in iPad application.

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        // for iPads
        // here you can use UIPopoverController   
    } else
    {
        // for iPhones
    }
    
    0 讨论(0)
  • 2021-02-11 03:02

    This must just work for you guys

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"popoverSegue"])
    
        {
            UIViewController *popUpControl=segue.destinationViewController;
            popUpControl.modalPresentationStyle=UIModalPresentationPopover;
            popUpControl.popoverPresentationController.delegate=self;
        }
    }
    -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
    {
        return UIModalPresentationNone;
    }
    
    0 讨论(0)
  • 2021-02-11 03:12

    UIPopoverController works on iPad only. In iOS 8 you can use UIPopoverPresentationController for both iPhone and iPad, and there's a small trick to make it look like UIPopoverController which is explained HERE.


    Here's the Objective-C version of the swift code you see in the link I provided.

    @interface SomeViewController : UIViewController <UIPopoverPresentationControllerDelegate>
    @end
    
    @implementation SomeViewController
    
    -(void) prepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender 
    {
        if ([segue.identifier isEqualToString:@"PopoverSegue"]) {
            UIViewController *controller = segue.destinationViewController;
            controller.popoverPresentationController.delegate = self;
            controller.preferredContentSize = CGSizeMake(320, 186);                
        }
    }
    
    // MARK: UIPopoverPresentationControllerDelegate
    
    -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller 
    {
        // Return no adaptive presentation style, use default presentation behaviour
        return UIModalPresentationNone;
    }
    @end
    
    0 讨论(0)
提交回复
热议问题