【问题标题】:modalPresentationStyle not working in modal view in iOS5modalPresentationStyle 在 iOS5 的模态视图中不起作用
【发布时间】:2012-01-10 13:18:07
【问题描述】:

我想在 iOS5 中使用 UIView 的 presentModalViewController 方法在 iPad 中显示一个弹出窗口。

即使我将 modalPresentationStyle 设置为 UIModalPresentationFormSheet,它也只显示为全帧大小。

我之前在iOS4中使用过相同的代码,它可以显示为弹出窗口。如何在 iOS5 中修复它?


DetailViewController *d = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
self.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:d animated:YES];

谢谢。

【问题讨论】:

  • 你能告诉我们你正在使用的代码吗?
  • 原帖中添加的代码。

标签: ios ipad ios5


【解决方案1】:

你试过了吗

d.modalPresentationStyle = UIModalPresentationFormSheet;

而不是

self.modalPresentationStyle = UIModalPresentationFormSheet;

【讨论】:

  • 它崩溃了。无论如何,我自己解决了这个问题。谢谢。
  • 请将解决方案发布为答案。
【解决方案2】:

在iOS5中,模态视图应该如下使用。


DetailViewController *d = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:d];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:navigationController animated:YES];

【讨论】:

  • 这个答案具有误导性。不需要额外的 UINavigationController 层。您的代码中可能存在错误,因为 DetailViewController 依赖于包含在 UINavigationController 中,这就是 @KIDdAe 的建议使其崩溃的原因。
猜你喜欢
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 2011-12-22
  • 1970-01-01
  • 2021-02-08
  • 2011-12-12
  • 2011-12-20
  • 1970-01-01
相关资源
最近更新 更多