0

Probably a simple question but I haven't found a solution. I have several view controllers with some sliders that when dragged, input numbers into a label. I also want to have a simple popup keypad enter numbers into this same label. I created a view controller called Keypad and when a button is tapped on the current view controller I do this:

 - (IBAction)callKeypad:(id)sender
{
    Keypad *keypadController = [[Keypad alloc] initWithNibName:@"Keypad" bundle:nil];
   self.keypadViewController = keypadController;
   [self.view addSubview:keypadController.view];

    [keypadController release];

The keypad pops up with the current view controller still visible in the background. When I tap the numbers on the keypad I want the results to show instantly in the current view controller. I guess what I am trying to do is have one view controller send its output to another view controller.

Thanks for any help.

ennuikiller
  • 46,381
  • 14
  • 112
  • 137
Jim Smith
  • 3
  • 2

2 Answers2

1

You should create a delegate protocol that the main object conforms to so the Keypad can send messages to its delegate (the main object).

See this question on how to create a delegate protocol: How do I create delegates in Objective-C?

Community
  • 1
  • 1
Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
1

You have quite a lot of options.

  1. Like Alexsander Akers said you could use a delegate and a Protocol.
  2. Another option is the NSNotificationCenter which allows you to send messages to ANY other class that has registered interest.
  3. The easiest/ugliest option is to create a update method in your 'owning' view and pass in the owning view to the subview and have the subview call that update method when needed.
willcodejavaforfood
  • 43,223
  • 17
  • 81
  • 111