2012-08-05 75 views
3

試圖在主UIViewController的UIView子類上設置UIColor變量。我有一個屬性用於檢索UIViewController中請求的顏色,並且我有一個屬性用於在UIView上接收顏色。然而,當我使用點方法來應用所檢索的色我得到一個錯誤「屬性‘brushColor無法從UIViewController訪問UIView的UIColor屬性

//Controller.h’在類型‘的UIView *’的對象中沒有發現」

@interface ViewController : UIViewController { 
    UIColor *colorPicked; 
    UIView *drawScreen; 
} 
@property (nonatomic, strong) UIView *drawScreen; 

@property (nonatomic, strong) UIColor *colorPicked; 

//Controller.m

@implementation ViewController 

@synthesize drawScreen; 
@synthesize colorPicked; 

- (void)viewDidLoad{ 
    self.drawScreen = [[DrawingView alloc] initWithFrame:CGRectMake(0, 44, 1024, 724)]; 
    drawScreen.backgroundColor = [UIColor clearColor]; 

    drawScreen.brushColor = self.colorPicked; //This line errors stating the property is not available on type (UIView *) 

    [self.view addSubview:drawScreen]; 


    [super viewDidLoad]; 
} 

//View.h

@interface DrawingView : UIView{ 

    UIColor *brushColor; 

    UIBezierPath *myPath; 
} 


@property (nonatomic, retain) UIColor *brushColor; 

@end 

//View.m

@implementation DrawingView 

@synthesize brushColor; 

- (void)drawRect:(CGRect)rect{ 

    myPath = [[UIBezierPath alloc] init]; 

    [brushColor setStroke]; 

    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; 

} 

@end 

回答

5

您已聲明drawScreenUIView,在.H改變其聲明

@property (nonatomic, strong) DrawingView *drawScreen; 

,改變伊娃聲明匹配(或由於您使用性能反正完全刪除)