1

I'm trying to use methods to pass values from text fields in one view to corresponding text fields in another view. The action valuesChanged is wired to the event "Editing Did End" on the text fields. I tried using "Value Changed" with similar results (it doesn't work.). The only warning I receive is in a method call.

Here's the code for the VolumeViewController:

@implementation VolumeViewController

@synthesize boxWidth;
@synthesize boxHeight;
@synthesize boxLength;
@synthesize sphereRadius;
@synthesize boxResult;
@synthesize sphereResult;
@synthesize areaViewController;

-(IBAction)valuesChanged:(id)sender
{   
    NSString *length = boxLength.text;  
    NSString *width = boxWidth.text;
    NSString *radius = sphereRadius.text;

    NSLog(@"length: %@", length);       
    NSLog(@"width: %@", width);
    NSLog(@"radius: %@", radius);

    [areaViewController changeValues:width :length :radius];
}

-(void)changeValues:(NSString*)widthString :(NSString*)lengthString :(NSString*)radiusString
{
    boxWidth.text = widthString;
    boxLength.text = lengthString;
    sphereRadius.text = radiusString;
}

As you can see, the valuesChanged action instantiates three NSString objects, each corresponding to the text properties of a text field. These strings are then passed to the changeValues method of the areaViewController. The areaViewController's changeValues method is identical to the volumeViewController's method, other than the text field names being different. However, the NSLog commands that I have never show anything in the console, so it's obvious that despite my text fields being connected to the action, it is not being called. What do I need to fix?

The warning is given after the method call "[areaViewController changeValues:width :length :radius], and it reads 'UIViewController' may not respond to '-changeValues:::'

Joe
  • 56,979
  • 9
  • 128
  • 135
Michael
  • 11
  • 2

3 Answers3

2

Define the method it in your header.

unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62
  • The valuesChanged method is declared in the header. Do I need to declare the changeValues action as well? If So, how do I do that? – Michael Mar 30 '11 at 20:30
  • You can either declare the method in the header as you would any other method, or - if you'd rather keep it "private" (scare quotes as Objective-C doesn't have actually private methods) - see http://stackoverflow.com/questions/172598/best-way-to-define-private-methods-for-a-class-in-objective-c – marramgrass Mar 30 '11 at 20:52
2

What you can do to "declare" it in .m an not in .h (because it's kind of a private method for you, and it should not visible from outside) is add this before @implementation VolumeViewController :

@interface VolumeViewController()

- (void)changeValues: : : ;

@end

EDIT: It's better to name all the arguments in your method name. The signature should be:

-(void)changeWidth:(NSString*)widthString lenght:(NSString*)lengthString radius:(NSString*)radiusString;

This is more readable when you use it:

[areaViewController changeWidth:@"4" length:@"2" radius:@"6"];

Ludovic Landry
  • 11,606
  • 10
  • 48
  • 80
1

You are calling changeValues on areaViewController, but you have defined that method for the VolumeViewController class

Try changing [areaViewController changeValues:width :length :radius];
to [self changeValues:width :length :radius];

antalkerekes
  • 2,128
  • 1
  • 20
  • 36