0

I am working on a app, which uses UIPopoverController, I am getting a problem in presenting that popover, I have a UIView which is added on self.view, and a tableview added on that view, that table view has a custom cell, which includes a UITextField, on didBeganEditing method I need popover to open.

Here is the code:

   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];

I will getting following exception

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'

Regexident
  • 29,441
  • 10
  • 93
  • 100
Rana Anees
  • 307
  • 2
  • 13
  • See this http://stackoverflow.com/questions/3377001/popovers-cannot-be-presented-from-a-view-which-does-not-have-a-window – Hawk-Eye May 24 '13 at 11:55

1 Answers1

1

here you present popoverview in the cell and give the Rect to popover of UITableViewController and so you get this error.. here it have not view hierarchy so its not get window and crashed here just follow the view hierarchy.

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • what should be the hierarchy? – Rana Anees May 24 '13 at 11:37
  • Every thing was working good but when I added a new view along with all things then it start crashing. Now if i add in self.view instead of Cell then it working but postion of popover is wrong – Rana Anees May 24 '13 at 11:39
  • it means you add any UIControls means UIView or UITableView in self.view or any other view then it means hierarchy. i just want to tell you that if you want to display any controls then its have must one based view like if you want to display image then you add in `UIView` like `[self.view addSubviews:imgview];` so just maintain the flow.. :) – Paras Joshi May 24 '13 at 11:39
  • @RanaAnees yes exactly i just tell you that if you add it in self.view or any scrollview then its working fine but it not worked in cell bcoz it have not window .. – Paras Joshi May 24 '13 at 11:40
  • @RanaAnees hey see this answer now i found that another answer see http://stackoverflow.com/questions/10965114/uipopovercontroller-and-uiimagepickercontroller-crash – Paras Joshi May 24 '13 at 11:42