HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – UISplitViewController:如何呈现popover?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个UISplitViewController,它是一个带有以下委托方法的UISplitViewControllerDelegate:

当iPad在PorTrait中启动时,我希望可以看到SplitView中的Popover.我怎样才能做到这一点?

我试过以下代码

- (void)splitViewController:(UISplitViewController *)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem *)barButtonItem
       forPopoverController:(UIPopoverController *)pc
{
    //setTing the barButtonItem in the toolbar in the detail view.

    [pc presentPopoverFromBarButtonItem:barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}

但上面的代码给了我以错误

解决方法

只有一个问题,错误的地方调用presentPopover方法,splitViewController:* WillHide * ViewController …….所以,barButtonItem存在但不存在于屏幕上.我使用下一个代码,它对我有用.
对于处理所有情况,您需要使用2种方法.

- (void)viewDidAppear:(BOOL)animated
{
    if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPorTrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPorTraitUpsideDown) {
        if (self.view.window != nil) {
            [_masterPopoverController presentPopoverFromRect:CGRectMake(0,1,1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
        }
    }
    [super viewDidAppear:animated];
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    if (fromInterfaceOrientation == UIDeviceOrientationLandscapeLeft || fromInterfaceOrientation == UIDeviceOrientationLandscapeRight) {
        if (self.view.window != nil) {
            [_masterPopoverController presentPopoverFromRect:CGRectMake(0,1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
        }
    }
}

大佬总结

以上是大佬教程为你收集整理的objective-c – UISplitViewController:如何呈现popover?全部内容,希望文章能够帮你解决objective-c – UISplitViewController:如何呈现popover?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。