It is really strange that for a Single View app, I added a MainView class and made the ViewController.xib to use custom class of MainView, and catch the touchesMoved event in ViewController.m, and record the dot (the location).
Then in drawRect inside MainView.m, I draw the dot. So when the program runs, all I see is a single dot on the screen, drawn to where my finger moves to…
However, as soon as I added initWithCoder to MainView.m, the behavior is totally different. It seems like the view won’t clear its content before drawing the dot, and all the dots previously drawn remain on screen, but the screen flashes a lot (I am using the new iPad with the new GPU)… seems like there are several “buffers”, some with different sets of old dots, and another buffer had different set of old dots… When my finger left the screen, it could be one of those buffers (a random buffer with different set of dots). (one more thing: the background of the screen changed to all black. Before, it was grey or whatever color Interface Builder set the view to). Why does adding the initWithCoder as follow will create such effect?
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
}
return self;
}
Your
initWithCoder:method is wrong. You have to call[super initWithCoder:aDecoder], not plain old[super init], otherwise all the information from the xib file (including the redraw options and background colour) is lost – theaDecoderobject contains all this information, and you are discarding it.