jejku, to chyba podstawy myślenia obiektowego IMO (obiekty współdzielą ze sobą inne obiekty)
a szczególnie w Obj-C i jego zarządzaniu pamięcią
Bar - twoje menu z efektami
ma działać na UIImage - no to ma taką property
Bar.h
Kod:
@interface Bar : NSObject {
}
@property (nonatomic, retain) UIImage *image;
- (void) doSomethingWithImage;
@end
Bar.m
Kod:
#import "Bar.h"
@implementation Foo
@synthesize image = _image;
- (void) dealloc
{
[_image release];
[super dealloc];
}
- (void) doSomethingWithImage
{
[self.image doSomething];
}
@end
klasa Foo - twój ViewController, będzie mieć w sobie obiekt klasy Bar
Foo.h
Kod:
#import "Bar.h"
@interface Foo : NSObject {
}
@property (nonatomic, retain) UIImage *image;
- (void) loadBar;
@end
Foo.m
Kod:
#import "Foo.h"
@implementation Foo
@synthesize image = _image;
- (id) init
{
if(self = [super init]) {
_image = [[UIImage alloc] initWithContentsOfFile:@"fileName"];
}
}
- (void) dealloc
{
[_image dealloc];
[super dealloc];
}
- (void) loadBar
{
Bar *bar = [[Bar alloc] init];
bar.image = self.image; // tutaj siedzi cała magia
[self addSubview:bar];
[bar release];
}
@end
tworzysz sobie obiekt klasy Bar, ustawiasz mu odpowiedni UIImage jako jego property (w końcu on ma na nim działać, a to tylko wskaźnik jest) i tyle. dodajesz go.
kminisz?