вот текущая ситуация:
TestViewController.h:
#import <UIKit/UIKit.h>
@interface TestViewController : UIViewController {
}
@end
TestViewController.m:
#import "TestViewController.h"
#import "draw.h"
@implementation TestViewController
- (void)viewDidLoad {
draw.rectColor = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1].CGColor;
[draw setNeedsDisplay];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[super dealloc];
}
@end
draw.h:
#import <UIKit/UIKit.h>
@interface draw : UIView {
UIColor* rectColor;
}
@property (retain) UIColor* rectColor;
@end
draw.m:
#import "draw.h"
@implementation draw
@synthesize rectColor;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
- (void)drawRect:(CGRect)rectangle {
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef myColor = [UIColor colorWithHue:0 saturation:1 brightness:0.61 alpha:1].CGColor;
CGContextSetFillColorWithColor(context, myColor);
CGContextAddRect(context, CGRectMake(0, 0, 95.0, 110.0));
CGContextFillPath(context);
}
- (void)dealloc {
[super dealloc];
}
@end
затем в Интерфейсном Разработчике я создал UIView 90x115 и установил его Class Identity на "draw".Когда я запускаю приложение (без двух некомпилируемых строк), оно отображает красивый красный прямоугольник в середине экрана.Моя цель состоит в том, чтобы иметь возможность изменить цвет прямоугольника из моего TestViewController.Однако, когда я компилирую тестовое приложение, я получаю следующие ошибки компилятора:
error: accessing unknown 'setRectColor:' class method
error: object cannot be set - either readonly property or no setter found
warning: 'draw' may not respond to '+setNeedsDisplay'
Я знаю, что мне не хватает "ссылки" между моим TestViewController и рисованием, но я не могу понять, как его реализовать.,Я пробовал разные трюки, но ничего не получалось.Может кто-нибудь объяснить, что нужно сделать, чтобы
draw.rectColor = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1].CGColor;
[draw setNeedsDisplay];
скомпилировал и работал?(Я бы использовал эти знания для создания другого метода в TestViewController, я просто тестирую его внутри viewDidLoad)