views:

80

answers:

1

Hey,

I know this question was already ask several times but i don't get it.

I have 2 classes classA.h & .m and classB.h and .m.

In classA.h i've got a UITextField *myTextfield. In classB i import the header of classA and define the class with @class classA. I also set classA *classa.

if i try to get the value of myTextfield like this myString = classA.myTextfield.text; nothing happens

any suggestions what i'm doing wrong here?

i would be so thankfull for an answer becaus without getting this done i can't continue coding :)

thanks!

+1  A: 

members of Objective-C classes are always private.

In order to access the members of another class, you need to create accessor methods to these properties. The easiest way to do this is is via properties.

Modifiy your classA.h to look like this

@interface classA : UITableViewController
{
  IBOutlet UITextField *myTextfield;
  ...
}
@property(retain, readonly) UITextField * myTextfield;
...
@end

Then modify classA.m to have

@implementation classA
@synthesize myTextfield;

Then when you need to use it in the other class use either

classa.myTextfield.text

Or preferably

[[classa myTextfield] text]

Edit:

Also make sure that myTextField is being set to some value, by hooking it up to some text field in Interface Builder. See a sample Interface Builder tutorial if this is the problem.

Brandon Bodnár
thanks for the fast reply!So what is if i change for example UITabeViewController to SuperClass or UIViewController? Dosn't this have any influence on the behaviour of the classes?
jacky
SuperClass is just a placeholder for your current super class. Since it is a UITableViewController, I will edit the example to match.
Brandon Bodnár
and how do i call a method?[classA addEntryToList];that doesn't call the method but why? method looks like this:- (void)addEntryToList;thanks
jacky
in classA i set an NSString:NSString *myString = @"viewDidLoad"; in classB i tried to get the value with:NSString *mystring2 = [classA myString];but that doesn't work. no compiler error only a warning because of an unused var.:(
jacky