tags:

views:

28

answers:

2

I have a UIImageView based class (lets call it classA) that uses a classB and was declared something like that...

@interface classA : UIImageView  {
    @public classB *mylabel;
}

@property (nonatomic, retain) classB *mylabel;


... @synthesize myLabel was put on its .m

class B was declared something like

@interface classB : UILabel  {
    @public UILabel *myCustomlabel;
}

@property (nonatomic, retain) classB *myCustomlabel;


... @synthesize myCustomlabel was put on its .m

now I am on the main code. I create an object like this

classA *myObject = [[classA alloc] init];
myObject.myLabel.myCustomLabel.text = @"Hi there";
// this last line fails. It says there's not myCustomLabel structure on myLabel!!!

why is this happening if everything is public?

thanks

+1  A: 

I am not sure if it is the typo or not but there is mistake between "l" and "L" in your code. It is likely that this creates your problem because you mess up between "l" and "L"

@public classB *mylabel;  // small "l"

@property (nonatomic, retain) classB *mylabel; // small "l"


... @synthesize myLabel was put on its .m  // big "L"






@interface classB : UILabel  {
    @public UILabel *myCustomlabel; // small "l"
}

@property (nonatomic, retain) classB *myCustomlabel;  // small "l"


... @synthesize myCustomlabel was put on its .m  // small "l"

So, I guess, for your code, when you call myObject.myLabel , it uses the get of the @property and @synthesize, then the next myCustomLabel, it doesn't find any (variable, property + synthesize) like that so it complains

Generally, if you already declare @property + @synthesize, you don't need and should'n have public variable. The @property generates public getter and setter method already

vodkhang
the L stuff is just a typo, as I had to simplify the code for posting here. The public stuff is because I need to access its values from the main code... but if you say the property generates the public getter and setter, I will remove it... thanks.
Digital Robot
If the L is just a typo then this is really strange, because if the compiler cannot see your public variable, it still has to use the public getter and setter
vodkhang
thanksssssssssssss!
Digital Robot
you're welcome, but finally, what is exactly your problem?
vodkhang
declaring @public was interfering in some strange way. Removing that solved the problem.
Digital Robot
+1  A: 

I guess there are some typos in your code.

@interface classB : UILabel { @public UILabel *myCustomlabel; }

@property (nonatomic, retain) classB *myCustomlabel; // Type should be UILabel not ClassB

classA *myObject = [[classA alloc] init]; myObject.myLabel.myCustomLabel.text = @"Hi there"; // myLable L should be in small

And ClassA.h and classB.h should be included in the code, where you are accessing the variable.

phoneix