I have an instance of UICollectionViewCell ( lets call it c ).
c has a property child of type B*
@property (strong) B* child;
in B there is a declaration
@property (strong) C* parent;
in C.m I set
self.child.parent = self
In B.m I have code :
position = self.parent.center.x;
For some reason I can not access center property of UIVIew from outside the instance. Is it private ? I looked in UIView.h and in the documentation. I dont see it being private.
Accessing self.parent in B.m is giving me the correct values …
So why cant I access it ? In C.m
self.center
is working as expected …
EDIT : With the real code
This is the so-called “C.h”
#import <UIKit/UIKit.h>
#import "UIMovableImage.h"
@interface LetterCollectionCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *letterCellView;
@end
This is “B.h”
#import <UIKit/UIKit.h>
@class LetterCollectionCell;
@interface UIMovableImage : UIImageView
{
CGPoint currentPoint;
}
@property (strong) LetterCollectionCell* parent;
@end
This is “C.m”
#import "LetterCollectionCell.h"
#import "LettersCollection.h"
@implementation LetterCollectionCell
-(void)PrepareImage:(int)index Hint:(BOOL)hint Rotate:(BOOL)rotate
{
if ([_letterCellView respondsToSelector:@selector(parent)])
{
UIMovableImage* temp = ((UIMovableImage*)self.letterCellView);
temp.parent = self;
}
}
@end
And here is the “B.m”
#import "UIMovableImage.h"
#import "LetterCollectionCell.h"
@implementation UIMovableImage
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
// Get active location upon move
CGPoint activePoint = [[touches anyObject] locationInView:self.parent];
// Determine new point based on where the touch is now located
CGPoint newPoint = CGPointMake(self.parent.center.x + (activePoint.x - currentPoint.x),
self.parent.center.y + (activePoint.y - currentPoint.y));
}
@end
Please note that the LetterCollectionCell’s letterCellView is of type UIImageView and not of type UIMovableImage. The reason is that I want to keep this declaration as a placeholder. In the Interface Builder I have two scenes where the LetteCollection is used. In one scene I set the imageview to be of UIMovableImage ( thru Inspector Window ) and at the other I left the image to be of type UIImageView. So the run-time will create the proper class upon different scenes and at the collection I check : if the image has a property “parent” – I set it up. Otherwise I dont.
It works fine, the assignment works just fine…. but the access is not
I found the reason.
The whole question was barking at the wrong tree.
In fact, the bug was at the other place and I just kept looking at the “Invalid Expression” int the debugger’s watch window.
To sum up : accessing the “center” property worked just find under the circumstances described in the original question. The “Invalid Expression” of the debugger and a bug in a different place made me chase a wrong thing.
I +1d the generally correct answers and comments but can not accept them since it may mislead people.
Thanks to all for the help and the effort