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];}
但上面的代码给了我以下错误:
解决方法 只有一个问题,错误的地方调用presentPopover方法,splitVIEwController:* WillHIDe * VIEwController …….所以,barbuttonItem存在但不存在于屏幕上.我使用下一个代码,它对我有用.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.’
对于处理所有情况,您需要使用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?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)