I have a customized UIView in which I do some low-level drawing in drawRect: method. It works fine when I instantiate the view in an XIB file. However, things go strange when I instantiate it programatically, e.g,
MyView *view = [[MyView alloc] initWithFrame: rect];
[self.view addSubView: view];
It appears that whenever drawRect: method runs, the resulting view contains the current drawing overlapped with some old drawings made in previous calls. In other words, it appears that the view has not been cleared out when drawRect: is called.