How can I connect one of my View with UIView class?

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.

Need Your Help

Best way to avoid out of memory exception in application

c# httpwebrequest out-of-memory

We are designing a Stress Test Application which will send mass HTTP requests of size "1 MB" to a particular Web Service. To achieve stress, we are using multiple threads in the application. Struct...

Looking for a Complete Delphi (object pascal) syntax

delphi syntax grammar

I need a complete Object Pascal syntax (preferably Delphi 2009). Some of the syntax is given by the help files, but not all information is provided. So I started collecting loose bits of information.