views:

924

answers:

4

I have MainViewController calling WebViewController (From UICatalog sample application) In WebViewController I make some function setValue(){...} to set some value passed as parameter to the variable (NSString *value) from WebViewController.h but when I try from MainViewController something like WebViewController targetViewController... targetViewController.setValue(value), it says: "error: request for member 'setValue' in something not s structure or union"...

+1  A: 

If you have a property named "value", and use @sythesize to create a method for you, in which case you call using that "." notation:

targetViewController.value = whatever;

Or you can call the setter outright regardless of you or the @synthesize writing the method:

[targetViewController setValue:whatever];

The property syntax (class.property = whatever) is really just a shortcut of calling a "setValue:" method, and in return the @property and @synthesize mechanisms of properties are just writing a helpful bit of code for you.

Edit: I had said before if you just wrote a "setValue:" method you could call it using the "class.value = newValue" notation, but that was incorrect - you have to define an @property to use "." notation.

Kendall Helmstetter Gelner
+1  A: 

I believe that

targetViewController.value = whatever;

will only work if you already have the @property declared; if not, you'll need to use the full method calling syntax:

[targetViewController setValue: whatever];

Otherwise, Kendall is correct about using setters and @synthesize.

Also your syntax is written using procedural C

targetViewController.setValue(value);

which definitely won't work.

Ben Gottlieb
Whoops on my part, you are totally correct - after testing you have to use @property to call using the class.value syntax. I'll edit my response so as not to spread false notions...
Kendall Helmstetter Gelner
A: 

Thanks for the answers, I solve my problem. Thanks again.

DFG
Could you please explain how did you solve it ?
Guido
A: 

You also need to be sure to #import your targetViewController.h file.

drewh