1

I have a popoverview with a table, and I want to pass back some data when I click on a cell, but I don't know how to do...

2 Answers2

5

Familiarize yourself with the delegate pattern. Define a method in a protocol for passing down the data. Set the view controller as the popover controller's delegate. The view controller should implement the protocol. In the popover controller pass this data when the button is pressed. In the view controller process this data accordingly.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
  • I made it all, ma I don't know how can I set he view controller as the popover controller's delegate... can you explain me? – Alessandro Belli May 07 '13 at 17:52
  • From the view controller call `popopverController.delegate = self;` after creating the popover controller before presenting it. – Hermann Klecker May 07 '13 at 18:00
  • OK, thank you, I've done It with this code: `- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"popover"]) { NSLog(@"%@",[segue destinationViewController]); self.popSegue = (UIStoryboardPopoverSegue*)segue; [[segue destinationViewController] setDelegate:self]; } }` – Alessandro Belli May 07 '13 at 21:29
0

Dude you can try delegates if the table view is in a different class or if table view is in the same class just see didSelectRowAtIndexPath:

Writing a delegate:

In .h file of popover table class:

@protocol PopOverSelectionDelegate;
@property (nonatomic,weak) id <PopOverSelectionDelegate> delegate;
@protocol PopOverSelectionDelegate 

@optional

- (void)popOverItemSelected:(NSString *)selectedItem;

@end

In .m file

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate popOverItemSelected: [yourArray objectAtIndex:indexPath.row]];
}
Satheesh
  • 10,998
  • 6
  • 50
  • 93