hello how can i call in the current view, a method implemented in the viewcontroller of the current view's superview? can you help me please. thanx
UIViews have no knowledge of their view controllers. You will need to create a custom UIView subclass that maintains a reference to one (or potentially more than one) view controller, although doing so introduces further coupling between UIView and UIViewController.
You should consider implementing the method in the superview's or view's class rather than implementing it in a view controller.
thank you so much... how can i then access superview's methods? i have access to the sdk's default methods but not the ones i have writen myself. this is "superview".h (trying to access drawChessBoardTab)
#import <UIKit/UIKit.h>
@interface EchiquierDisplayView : UIView {
IBOutlet UIViewController *chessPiecesDisplayViewController;
BOOL uperLeftCellColor; //uperLeftCellColor: YES->White, NO->Black;
}
@property (nonatomic, retain) UIViewController *chessPiecesDisplayViewController;
-(void) drawChessBoardTab: (CGContextRef) context:(float )boardWidth;
@end
this is "currentview".h
#import <UIKit/UIKit.h>
/*
* Les pieces seront de ce type
*/
@interface pieceDraggableImageView : UIImageView {
CGPoint startLocation;
CGPoint startLocationInView;
}
-(void)correctDestinationPosition;
@end
i think i should tell the views somehere that they are related... can you help me thanx
Typically this is done through delegates.
Have your view interface define a protocol and a reference to some delegate. Then have your parent viewcontroller implement this protocol.
Then the parent would do this:
someView.fooDelegate = self;
then the view would do something like this:
if(self.fooDelegate != nil) {
if([fooDelegate respondsToSelector:...]) {
[fooDelegate performSelector:...];
}
}
This is not compiled, but I think you get the gist.
You can add a function -(void)initWithView:(EchiquierDisplayView *)aSuperview or something like that, define a reference in your
@interface pieceDraggableImageView : UIImageView {
CGPoint startLocation;
CGPoint startLocationInView;
EchiquierDisplayView *theSuperview;
}
@property (nonatomic, retain) EchiquierDisplayView *theSuperview;
-(void)correctDestinationPosition;
-(void)initWithView:(EchiquierDisplayView *)aSuperview;
...
-(void)askSuperview;
@end
@implementation pieceDraggableImageView
...
-(void)initWithView:(EchiquierDisplayView *)aSuperview
{
theSuperview = aSuperview;
}
...
-(void) correctDestinationPosition
{
[theSuperview correctIt];
}
Now be sure to implement the function correctIt in your superview. Hopefully i understood your question right...