objective-c – UISplitViewController:如何呈现popover?

objective-c – UISplitViewController:如何呈现popover?,第1张

概述我有一个UISplitViewController,它是一个带有以下委托方法的UISplitViewControllerDelegate: splitViewController:willHideViewController:withBarButtonItem:forPopoverController: 当iPad在Portrait中启动时,我希望可以看到SplitView中的Popover.我怎 我有一个UISplitVIEwController,它是一个带有以下委托方法的UISplitVIEwControllerDelegate:

splitVIEwController:willHIDeVIEwController:withbarbuttonItem:forPopoverController:

当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];}

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

Terminating app due to uncaught exception ‘NSinvalidargumentexception’,reason: ‘-[UIPopoverController presentPopoverFromrect:inVIEw:permittedArrowDirections:animated:]: Popovers cannot be presented from a vIEw which does not have a window.’

解决方法 只有一个问题,错误的地方调用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?所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1079917.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存