I programmatically set up a popover, and try to present it in (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
with the following code:
popoverView.popoverContentSize = CGSizeMake(580, 760);
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[popoverView presentPopoverFromRect:cell.bounds inView:tableView permittedArrowDirections:(UIPopoverArrowDirectionAny) animated:YES];
This works fine, however, it ignores the size, so that the view gets cut off, because the cell is near the middle of the screen. When I change it to (UIPopoverArrowDirectionRight|UIPopoverArrowDirectionLeft), it also ignores this and displays the popover up or down.
What I want is for the popover to be displayed closer to the left side of the cell, so that it has space to open to the side, but I get a lot of errors with the tableview whenever I attempt to edit the rect it is displayed from... I have tried many different ways, for example:
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect frame = CGRectMake(cell.bounds.origin.x, cell.bounds.origin.y, cell.bounds.size.width/4, cell.bounds.size.height);
[popoverView presentPopoverFromRect:frame inView:tableView permittedArrowDirections:(UIPopoverArrowDirectionAny) animated:YES];
and no matter what I do, unless I use the first code (FromRect: cell.bounds inView:tableView) I get the two following errors:
Assertion failure in -[UIPickerTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:8357*
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource is not set'*
But the tableview datasource is definitely set, and I only get these errors when I tried to change the rect the popover is presented from. I have also tried to manually calculate the position of the cell to get the frame instead of using the cell, aka by multiplying the height of cells by indexPath.row for the y value...
Any ideas as to why I'm getting these errors?? Or how I can display the full popover properly from the tableview?
Edit: Also, there's no issues with me getting the cell and creating a frame based on the cell's bounds.. The line where the errors come from is always on the "presentPopoverFromRect:" line.
Solution: I was finally able to achieve the desired affect of having the popover not from the center of the cell with a CGRectOffset without any errors:
CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath] toView:tableView];
[popoverView presentPopoverFromRect:CGRectOffset(rect, -400, 0) inView:tableView permittedArrowDirections:(UIPopoverArrowDirectionAny) animated:YES];
Another Edit: The really weird thing is that that code works for the first section I tested it in. But my tableview has 2 sections, and for some reason the popover is working fine in the second section, but I'm still getting the errors in the first section? Any ideas about the errors??