本文介绍了ios5.0和ios5.1之间的splitview poperver问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究了几乎所有可以找到的相关帖子,并且已经可以使用一些帮助了.

I've researched just about every post I can find on this and have reached the point where I could use some help.

我的项目是使用情节提要构建的通用应用程序. iPad版本使用拆分视图控制器.主视图关系是具有视图控制器的导航控制器.细节视图是带有视图控制器的导航控制器.

My project is a universal app built using storyboards. the iPad version uses a split view controller. Master view relatioship is a navigation controller with a view controller. Detail view is a navigation controller with a view controller.

在没有意识到的情况下,我使用iPad 5.1模拟器构建并测试了该应用程序.意识到这些小细节并需要与iOS 5.0兼容后,我开始在ios 5.0中进行测试.

Without realizing it I built and tested the app using iPad 5.1 simulator. Upon realizing that small detail and needing iOS 5.0 compatibility, I started testing in ios 5.0.

发生了两个大变化:a)拆分视图显示在一个弹出窗口中,而不是全屏显示,如5.1.1(我实际上更喜欢该弹出窗口),以及b)我的代码以编程方式隐藏并显示有效的弹出窗口/拆分屏幕在5.1中完美地在5.0中不起作用-显示"实际上使应用程序崩溃.我构建了两种方法来显示/隐藏弹出窗口以补充UI,而不仅仅是依靠方向更改.例如,我使用show方法将弹出框纵向放置在屏幕上,但是在选择了表格视图后将其删除.

two big changes occurred: a) the split view shows in a popover, rather then full screen like in 5.1.1 (I prefer the popover actually) and b) my code to programmatically hide and show the popover/splitscreen which worked flawlessly in 5.1 does not work in 5.0 - the "show" actually crashes the app. I built a couple of methods to show/hide the popover to complement the UI and not just rely on orientation changes. For instance, I used the show method to put the popover on the screen in portrait but remove it after selection of a tableview, etc.

因此,也许有人可以提供帮助.以下是详细信息和问题-非常感谢您的帮助:

So, maybe someone can help. Here are the details and the questions - thanks so much in advance for your kind help:

iOS 5.1-显示弹出窗口-我使用splitview控制器委托调用来获取对弹出按钮的引用,然后使用按钮动作来显示方法的弹出窗口.在5.1中可以正常使用,但在5.0中会导致此错误:错误:无法从没有窗口的视图中显示弹出窗口. (我已经搜索了此错误,并且有很多参考文献,但没有针对我的配置的具体答案).再加上为什么在5.1而不是5.0中有可用的窗口?

iOS 5.1 - show pop up - I use the splitview controller delegate call to grab a reference to the popover button, then use the button action to show the popover from a method. This works perfect in 5.1 but caused this error in 5.0: ERROR: Popovers cannot be presented from a view which does not have a window.' (I've searched on this error and there are many references but not a specific answer for my configuration). Plus why is there a window available in 5.1 and not 5.0?

//show master view popover
[self.masterPopoverController presentPopoverFromBarButtonItem:self.showMasterViewButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

//get the reference from the button
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)newpopoverController
{
self.showMasterViewButton = [[UIBarButtonItem alloc]initWithTitle:nil style:UIBarButtonItemStyleDone target:barButtonItem.target action:barButtonItem.action];
}

这里的第一个观察结果是该按钮实际上在5.0和5.1中都可用,并且显示并在导航栏上起作用.但是,在代码中引用相同的按钮会导致在5.0上崩溃并在5.1上运行.我不知道为什么.

First observation here is that the button is actually available in both 5.0 and 5.1 and shows and works on the nav bar. However referencing the same button in code causes the crash on 5.0 and works on 5.1. I don't know why.

在iOS 5.0中将其隐藏的相同问题.在iOS 5.1中就是使用这种方法:

Same issue for hiding it in ios 5.0.in iOS 5.1 is use this approach:

    if (self.masterPopoverController) {
    [self.masterPopoverController dismissPopoverAnimated:YES];
}

self.masterPopoverController在上面列出的相同splitview委托回调中设置.这在iOS 5.1上完美运行,但在iOS 5.0中没有任何作用

self.masterPopoverController is set in the same splitview delegate callback listed above.this works perfect in iOS 5.1 but does nothing in iOS 5.0

注意-更新:我在这里找到了解决我列出的第一个问题的答案: https://github.com/mattgemmell/MGSplitViewController/pull/31 解决我列出的第一个问题.

NOTE - UPDATED: I found an answer here to resolve the first issue I listed: https://github.com/mattgemmell/MGSplitViewController/pull/31to fix the first issue I listed.

//grab a reference to the popover controller in the split view delegate call
//splitview ... willHideViewController
self.masterPopoverController = popoverController;

//then add the following to a method and call it when you need it
//this fixes the no window issue in iOS 5.0
[self.masterPopoverController presentPopoverFromRect:CGRectZero inView:[[UIApplication sharedApplication] keyWindow] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

  • 第二个问题是为什么将弹出窗口更改为幻灯片,并且可以在iOS 5.1中将其更改回幻灯片.我实际上很喜欢我的应用程序在iOS 5.0中的弹出效果,但是我无法将幻灯片更改为使用弹出效果.我尝试了多种方法来在多个位置更改弹出框的内容大小,但是它似乎对拆分视图弹出框没有影响,而类似的代码在其他杂项上也可以正常工作.按钮弹出窗口.
  • 我一定错过了,但是我假设苹果是故意这样做的,但是必须有一种方法可以覆盖吗?

    I must have missed this, but I'm assuming apple did this on purpose, but there must be a way to override?

    注意:找到一种解决方案或至少一种方法来模拟ios5.1上的ios5.0行为

    NOTE: found a resolution or at least a way to emulate ios5.0 behavior on ios5.1

    创建一个属性来保存一个UIViewController,另一个属性来保存一个UIPopoverController

    create a property to hold a UIViewController and another one to hold a UIPopoverController

    然后在拆分视图委托回调中获取主视图控制器的副本

    then in the split view delegate callback grab a copy of the master view controller

    - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)newpopoverController {
    
    self.copyOfMasterViewController = viewController;
    }
    

    然后将这样的方法添加到您的项目中:

    then add a method to your project like this:

    -(void)showsPopover {
      self.ios51popover = [[UIPopoverController alloc]initWithContentViewController:self.masterViewInPopover];
    
     [self.ios51popover setPopoverContentSize:CGSizeMake(320, 580) animated:NO];
     [self.ios51popover presentPopoverFromRect:CGRectMake(50, 55, 1, 1) inView: [[UIApplication sharedApplication] keyWindow] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    

    -(void)hidePopover { [self.ios51popover dismissPopoverAnimated:YES]; }

    -(void)hidesPopover { [self.ios51popover dismissPopoverAnimated:YES]; }

    现在,您已经拥有了.

    推荐答案

    第一个代码片段显示了如何以编程方式在ios5.0和5.1中工作的拆分视图中显示弹出窗口,并修复了无法从没有视图的视图中显示弹出窗口的情况.一个窗口.注意-更新:我在这里找到了解决我列出的第一个问题的答案: https://github.com com/mattgemmell/MGSplitViewController/pull/31 来修复我列出的第一个问题.

    This first snippet shows how to display the popover in a split view programmatically that works in ios5.0 and 5.1 and fixes the Popovers cannot be presented from a view without a window.NOTE - UPDATED: I found an answer here to resolve the first issue I listed: https://github.com/mattgemmell/MGSplitViewController/pull/31 to fix the first issue I listed.

    //在拆分视图委托调用中获取对弹出控件的引用//splitview ... willHideViewController

    //grab a reference to the popover controller in the split view delegate call//splitview ... willHideViewController

    self.masterPopoverController = popoverController;
    

    //然后将以下内容添加到方法中,并在需要时调用它//这解决了iOS 5.0中的无窗口问题 [self.masterPopoverController presentPopoverFromRect:CGRectZero inView:[[UIApplication sharedApplication] keyWindow] allowedArrowDirections:UIPopoverArrowDirectionAny animation:YES];

    //then add the following to a method and call it when you need it//this fixes the no window issue in iOS 5.0 [self.masterPopoverController presentPopoverFromRect:CGRectZero inView:[[UIApplication sharedApplication] keyWindow] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    下一个代码片段显示了如何以ios5.0样式呈现真实的弹出窗口,而不是苹果在iOS 5.1中实际使用的幻灯片

    This next snippet shows how to present a real popover in the ios5.0 style rather than the slide in effect apple went to in iOS 5.1

    注意:已更新:找到解决方案或至少一种方法来模拟ios5.1上的ios5.0行为创建一个属性来保存一个UIViewController,另一个属性来保存一个UIPopoverController

    NOTE: UPDATED: found a resolution or at least a way to emulate ios5.0 behavior on ios5.1create a property to hold a UIViewController and another one to hold a UIPopoverController

    然后在拆分视图委托回调中获取主视图控制器的副本

    then in the split view delegate callback grab a copy of the master view controller

    - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)newpopoverController {
    
    self.copyOfMasterViewController = viewController;
    }
    

    然后将这样的方法添加到您的项目中:

    then add a method to your project like this:

    -(void)showsPopover {
      self.ios51popover = [[UIPopoverController   alloc]initWithContentViewController:self.copyOfMasterViewController];
    
     [self.ios51popover setPopoverContentSize:CGSizeMake(320, 580) animated:NO];
     [self.ios51popover presentPopoverFromRect:CGRectMake(50, 55, 1, 1) inView: [[UIApplication sharedApplication] keyWindow] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    
    -(void)hidesPopover { [self.ios51popover dismissPopoverAnimated:YES]; }
    

    这篇关于ios5.0和ios5.1之间的splitview poperver问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 14:28