0

I have two views A and B. They are booth in the same controller as subviews of a main UIVIew. View A has a button. I want that button to throw an event when it gets touched which will be listen by view B. How should I make that?

Nuno Santos
  • 1,476
  • 3
  • 17
  • 34
  • Check out [NSNotificationCenter](http://stackoverflow.com/questions/2191594/how-to-send-and-receive-message-through-nsnotificationcenter-in-objective-c). Dead simple. – Patrick Perini Oct 20 '11 at 18:43
  • thanks for your replies! they were booth usefull for my database of knowledge!! :) – Nuno Santos Oct 25 '11 at 07:00

1 Answers1

0

I'll assume your views A & B are UIViews (instead of, maybe, subclasses of UIView where you could simplify things by making view A an UIButton). So, I guess the simplest solution would be to create an UITapGestureRecognizer and hook its callback to your other view.

Basically, something like this:

UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:YOUR_TARGET_OBJECT action:@selector(YOUR_CALLBACK_NAME)];

//your A view
[a addGestureRecognizer:tap];
[tap release];
Ivan
  • 330
  • 2
  • 9
  • No, in this case I can't make this views a button since this views hold buttons. I ended up making a protocol but I still think that this isn't the best solution. – Nuno Santos Oct 25 '11 at 07:07