【问题标题】:Present UIPopoverviewcontroller呈现 UIPopoverviewcontroller
【发布时间】:2013-05-19 23:32:45
【问题描述】:

我正在开发一个使用 UIPopoverController 的应用程序,我在呈现该弹出窗口时遇到问题,我在 self.view 上添加了一个 UIView,并在该视图上添加了一个 tableview,该表视图有一个自定义单元格,其中包括一个UITextField,在didBeganEditing 方法上我需要弹出框才能打开。

代码如下:

   table = [[UITableView alloc]initWithFrame:CGRectMake(textField.frame.origin.x,textField.frame.origin.y,200,100) style:UITableViewStylePlain];

table.tag=3;
[table setDataSource:self];
[table setDelegate:self];
[table reloadData];
UITableViewController *tableViewController= [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
tableViewController.tableView = table;

popOver= [[UIPopoverController alloc]
          initWithContentViewController:tableViewController];

[popOver  presentPopoverFromRect:popRect inView:cell permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

我会得到以下异常

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]:无法从没有窗口的视图中呈现弹出框。”

【问题讨论】:

标签: iphone ios ipad ios5 ios4


【解决方案1】:

在这里,您在单元格中显示 popoverview 并将 Rect 提供给UITableViewController 的弹出窗口,因此您收到此错误。这里它没有视图层次结构,因此它没有获取窗口并在此处崩溃,只需遵循视图层次结构。

【讨论】:

  • 层次结构应该是什么?
  • 一切都运行良好,但是当我添加新视图以及所有内容时,它开始崩溃。现在,如果我添加 self.view 而不是 Cell 那么它可以工作但弹出框的位置是错误的
  • 这意味着你添加任何 UIControls 意味着 UIView 或 UITableView 在 self.view 或任何其他视图中,然后它意味着层次结构。我只想告诉你,如果你想显示任何控件,那么它必须有一个基于视图,比如如果你想显示图像,那么你添加UIView 就像[self.view addSubviews:imgview]; 这样就保持流程.. :)跨度>
  • @RanaAnees 是的,我只是告诉你,如果你将它添加到 self.view 或任何滚动视图中,那么它工作正常,但它不能在单元格中工作,因为它没有窗口 ..
  • @RanaAnees 嘿,现在看到这个答案我发现另一个答案看到stackoverflow.com/questions/10965114/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-24
相关资源
最近更新 更多