1
votes

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:::'

3

3 Answers

2
votes

Define the method it in your header.

2
votes

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"];

1
votes

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];