5St*_*yan 2 cocoa-touch objective-c uipopover ios5
我使用提供的模板创建了一个裸骨主/细节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];
}
Run Code Online (Sandbox Code Playgroud)
当应用程序首次加载时选择弹出窗口时,一切看起来都很棒.但是,当用户单击回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];
}
Run Code Online (Sandbox Code Playgroud)
但是,这没有效果.此外,一旦弹出窗口关闭(通过旋转或取消选择UI上的弹出窗口),先前在堆栈上推送的最大表视图控制器的弹出框大小仍然保留并完全忽略上述尺寸.我错过了什么?
我无法理解你的整个问题,但我认为你的问题的基础是一个不好的弹出窗口大小.
通常,Popover大小的问题来自于[UIViewController contentSizeForViewInPopover]只能在创建UIPopoverController实例之前设置的事实.它只是弹出窗口大小的默认值.
当您UIPopoverController使用控制器作为其内容创建实例时,会将其contentSizeForViewInPopover复制到[UIPopoverController popoverContentSize]并且永远不会再次读取.如果在内容上更改它,则不会更新弹出窗口大小.
如何更改已创建UIPopoverController实例的大小的唯一方法是使用属性[UIPopoverController popoverContentSize]或方法[UIPopoverController setPopoverContentSize:animated:].
| 归档时间: |
|
| 查看次数: |
2448 次 |
| 最近记录: |