I have a board (UIViewController) which instantiates card objects (UIViewControllers). On each card there’s a texfield. In order to remove the keyboard by clicking on the non card area (= view of the board) I need a reference to the board specified in the UITapGestureRecognizer. Here’s my current approach.
Board (UIViewController) Initializing a card object
-(void) addCard:(id)touchEvent{
CardViewController *card = [[CardViewController alloc]initItemWithText:@"..."];
[self addChildViewController:card];
[self.view addSubview:card.view];
}
Card (UIViewController) On init, add Tap Gesture Recognizer
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
...
UITapGestureRecognizer *tapBackground = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapBackground:)];
[self.parentViewController.view addGestureRecognizer:tapBackground];
...
}
The “background” reference using the parentViewController method doesn’t seem to work. Why?
How can I reference from the card back to the board to resign the card’s first responder on tap?
Try add the gesture code to Board instead of Card (in viewDidLoad)