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.
2
votes
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
Storyboard_iPad.storyboard: Couldn't compile connection: <IBCocoaTouchOutletConnection:0x7faf954540e0 <IBProxyObject: 0x7faf95455040> => anchorView => <IBUIButton: 0x7faf9556cc20>>
– user3522400
Are you using prototype cells?
– Paulw11
4 Answers
3
votes
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.
0
votes