2

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.

warvariuc
  • 57,116
  • 41
  • 173
  • 227
user3522400
  • 21
  • 1
  • 5
  • 1
    Can you provide the details of the error message you are receiving? Are you using prototype cells for your UITableView? If so then that is most likely your problem - you cannot launch a segue from a prototype object. You will need to implement an event handler for your button and trigger your segue programatically – Paulw11 Apr 11 '14 at 07:01
  • Storyboard_iPad.storyboard: Couldn't compile connection: => anchorView => > – user3522400 Apr 11 '14 at 07:25
  • Are you using prototype cells? – Paulw11 Apr 11 '14 at 07:31

4 Answers4

4

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

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

Keshav
  • 2,965
  • 3
  • 25
  • 30
  • Thank you for your help.That compilation error is solved but my application is suddenly quit when application run show error ** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key segueButton.' – user3522400 Apr 11 '14 at 09:08
  • ok, you are using Segue Identifier as "segueButton" and you should give the same identifier in the storyboard for the segue you connected – Keshav Apr 11 '14 at 09:16
  • keshav:- http://stackoverflow.com/questions/23211126/core-data-table-relationship-and-fetchrequest i post one question.would you please help me for solve this problem... – user3522400 Apr 22 '14 at 05:33
  • i put one more question would please help me for solve this problem....http://stackoverflow.com/questions/23802117/nspredicate-for-time-interval/23802449? – user3522400 May 22 '14 at 10:56
3

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.

valfer
  • 3,545
  • 2
  • 19
  • 24
  • Hint: instead of re-instantiate every time the second view controller you could maintain it in a (strong) property and simply re-configure it at every button tap (but this is just an implementation choice). – valfer Apr 11 '14 at 08:02
0

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

Marcal
  • 1,371
  • 5
  • 19
  • 37
0

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

Keshav
  • 2,965
  • 3
  • 25
  • 30