views:

144

answers:

2

Hi, 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.

+1  A: 

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?

Alexsander Akers
Thanks for the response and the link. I will give the delegate protocol a whirl
Jim Smith
+1  A: 

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
Great..Thanks for all the options. I will play with 1 and 2 options to find my preference.
Jim Smith