我使用提供的模板创建了一个Bare Bones Master/详细信息iPad应用程序。它创建两个视图控制器(主和细节)。我已经创建了一个视图附加视图控制器,该控制器被弹出在主视图控制器之上(几乎要钻到桌面视图,直到最终击中一个填充详细信息的单元格。对于指定的维度(下面的代码还显示了从主视图控制器tableview选择选择时):

@implementation MasterViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.vehicles = [[NSArray alloc] initWithObjects:@"Cars", @"Trucks", @"Boats", nil];

        self.title = @"Vehicle Type";
        self.clearsSelectionOnViewWillAppear = NO;
        self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0);
    }
    return self;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.studySessionViewController)
    {
        self.secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    }
    [self.navigationController pushViewController:self.secondViewController animated:YES];
}

当应用程序首次加载时选择弹出窗口时,一切看起来都很好。但是,当用户单击回到MasterViewController时,弹出式的大小与堆栈上推动的最大视图控制器的大小相同。我已经四处搜索,并且已经在主视图控制器类中添加了以下代码:

- (void)viewWillAppear:(BOOL)animated
{
    self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0);
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0);
    [super viewDidAppear:animated];
}

但是,这没有影响。同样,一旦关闭了弹出窗口(通过旋转或取消选择UI上的弹出窗口),以前最大的表观视图控制器的弹出尺寸仍然保留在堆栈上,并且完全忽略了上述尺寸。我想念什么?

有帮助吗?

解决方案

我无法理解您的整个问题,但我认为您的问题的基础是弹出案的不良大小。

通常,弹出大小的问题出现了一个事实 [UIViewController contentSizeForViewInPopover] 只能在创建之前设置 UIPopoverController 实例。这只是弹出式大小的默认值。

当您创建 UIPopoverController 以您的控制器作为其内容的实例, contentSizeForViewInPopover 被复制到 [UIPopoverController popoverContentSize] 再也不会读书。如果您在内容上更改它,则不会更新弹出式大小。

您可以改变已经创建的大小的唯一方法 UIPopoverController 实例正在使用属性 [UIPopoverController popoverContentSize] 或方法 [UIPopoverController setPopoverContentSize:animated:].

其他提示

您正在尝试在MasterViewController本身中设置弹出式大小。这是问题所在。为了 self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0); 要工作,您将不得不在详细信息ViewController中使用此功能,因为详细信息ViewController是具有弹出窗口的controller。这里的基本思想是,您将大小设置在父视图控制器中,而不是控制器本身。

您将不得不设置框架。

incomingCallViewController = [[IncomingCallViewController alloc]initWithNibName:@"IncomingCallViewController" bundle:nil];
            [incomingCallViewController.view setFrame:CGRectMake(400, 200, 377, 243)];

            [self.navigationController pushViewController:incomingCallViewController.view]; 

当然,这是我一个项目中的示例代码

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top