Popover segue not working

那年仲夏 提交于 2019-12-11 01:54:53

问题


I am developing one iPad application using storyboard. In my application i have 2 view controllers(First view controller and Modal view controller). In my first view controller I have one table view with cell containing one button. If I click the button in each cell I need to go to modal view controller. I connected the modal view controller and button by using a segue. Segue is working perfectly when style is modal but I need style Popover. When I am trying to change the segue style popover the storyboard error occurs and compilation failed comes. How can I solve this issue.


回答1:


Follow the steps in the image. hope I will help you.




回答2:


If the error is "Couldn't compile connection..." the problem is how XCode handles an outlet inside a dynamic table cell view.

I suggest you 2 alternatives:

1) The error doesn't come if you can use a "static" table view, in this way the table view must live inside a UITableViewController.

2) If you need a dynamic table, subclass the cell view and in your class (say MyUITableCellView) put an outlet:

@property (weak, nonatomic) IBOutlet UIButton *segueButton;

Then in your storyboard create an outlet from the prototype cell (of class MyUITableCellView) to the button inside the cell (do not create the segue in the storyboard, create only the destination view controller).

Then in the "cellForRowAtIndexPath" do the following:

MyUITableCellView *cell = (MyUITableCellView*)[tableView dequeueReusableCellWithIdentifier:@"MyCell"];
/* IMP: Here you should check if button has already this action (reused) */
[cell.segueButton addTarget:self action:@selector(showPopover:) forControlEvents:UIControlEventTouchUpInside];

and then add the action:

- (void)showPopover:(UIButton*)sender
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *secondVC = [storyboard instantiateViewControllerWithIdentifier:@"secondVC"];  // this is the storyboard id
    self.popover = [[UIPopoverController alloc] initWithContentViewController:secondVC];
    CGRect fromRect = [self.view convertRect:sender.frame fromView:sender.superview];
    [self.popover presentPopoverFromRect:fromRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

Hope this has helped.




回答3:


Have you included the <UIPopoverControllerDelegate> and implemented it? That's easy to forget the first times.




回答4:


May be you might have not connected the Anchor, put UIView in your Viewcontroller view somewhere with background colour clear and set Anchor point of the Segue to that view.....



来源:https://stackoverflow.com/questions/23005369/popover-segue-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!