user3522400
user3522400

Reputation: 21

Popover segue not working

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.

Upvotes: 2

Views: 3825

Answers (4)

Keshav
Keshav

Reputation: 3283

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

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

Upvotes: 4

valfer
valfer

Reputation: 3545

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.

Upvotes: 3

Keshav
Keshav

Reputation: 3283

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.....

Upvotes: 0

Marcal
Marcal

Reputation: 1371

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

Upvotes: 0

Related Questions