UIView
서브 클래스했다
.h
@interface HistogramGraphPanel : UIView
@property (strong, nonatomic) UIView *graphView;
-(id)initWithDataset:(Dataset *)dataset;
@end
.m
-(id)initWithDataset:(Dataset *)dataset {
self = [super init];
if (self) {
self.dataset = dataset;
self.translatesAutoresizingMaskIntoConstraints = FALSE;
UIView *contentView = [UIView new];
contentView.translatesAutoresizingMaskIntoConstraints = FALSE;
contentView.backgroundColor = [UIColor orangeColor];
contentView.tag = 6;
self.contentView = contentView;
UIView *headerView = [UIView new];
headerView.translatesAutoresizingMaskIntoConstraints = FALSE;
headerView.backgroundColor = [UIColor blueColor];
self.headerView = headerView;
[headerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[headerView(60)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(headerView)]];
[contentView addSubview:headerView];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[headerView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(headerView)]];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[headerView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(headerView)]];
UILabel *headerLabel = [UILabel new];
headerLabel.translatesAutoresizingMaskIntoConstraints = FALSE;
headerLabel.font = [UIFont fontWithName:HELVETICA_FONT_STYLE_BOLD size:24];
headerLabel.text = @"Analysis Histogram";
headerLabel.backgroundColor = [UIColor clearColor];
[headerView addSubview:headerLabel];
[headerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[headerLabel]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(headerLabel)]];
[headerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[headerLabel]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(headerLabel)]];
[self createGraphView];
self = (HistogramGraphPanel *)contentView;
}
return self;
}
가 작성 및 UIView
서브 클래스를 사용 : 나는 액세스하려고 할 때까지
HistogramGraphPanel *graphPanel = [[HistogramGraphPanel alloc] initWithDataset:dataset];
[self.view addSubview:graphPanel];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[panel]-[graphPanel]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(graphPanel, panel)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(49)-[graphPanel]-(228)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(panel, graphPanel)]];
DLog(@"graphPanel.graphView: %@", graphPanel.graphView);
큰 작품을 graphPanel.graphView
:
2013-04-25 16:44:58.579 [15666:907] -[UIView graphView]: unrecognized selector sent to instance 0x1e0c8320
2013-04-25 16:44:58.580 [15666:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView graphView]: unrecognized selector sent to instance 0x1e0c8320'
및 인스턴스 0x1e0c8320
은 제가 만든 graphView의 contentView입니다.
속성에 액세스하려고 시도하지 않으면 충돌로 실행됩니다.
이상형?
바보 같은 질문, '@ graphView를 합성 했습니까?' –
최신 컴파일러에서는 @synthesize가 더 이상 필요하지 않습니다. – mrueg
mrueg가 말한 것. – Padin215