In my xib file I have some View. And I have PainView class (UIView). In the identity inspector I set PaintView
for this View, and made @property (strong, nonatomic) IBOutlet PaintView *paintView;
It was working Ok, until I desided to change draw method. I copied code from this file and pasted in PaintView.m (same with PaintView.h).
But it only works if I write
[self.view addSubview:[[PaintView alloc] initWithFrame:self.view.bounds]];
But it creates new layer over all other layers, buttons etc. And I need to connect this class with existing View.
I tried paintView = [[PaintView alloc] initWithFrame:self.view.bounds];
but it didnt work.
In console it always says invalid context:
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextGetBaseCTM: invalid context 0x0
<Error>: CGContextConcatCTM: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
Can you help me, please? Thanks in advance.
you need to implement another init method with the same initialization as in initWithFrame:
It's name is:
- (id)initWithCoder:(NSCoder *)coder
{
...
}
initWithCoder:
is the init method, that is called for view, loaded from NIB files.