Why is awakeFromNib not called when the view is visited again?
I would like to know if there is a method equivalent to awakeFromNib
.
My app has 2 views and the 2nd view has a subclass (UIView
) which I use to draw.
I use a timer which is called from awakeFromNib
in order to animate the drawing.
- (void) awakeFromNib
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:selfselector:@selector(ReDraw) userInfo:nil repeats:YES];
}
- (void) ReDraw
{
i++;
[self setNeedsDisplay];
}
Now when i go back to my first view and come back to this view the drawing is still on (awakeFromNib is not called again).
The time开发者_如何学JAVAr doesn't stop when i go back to the first view. I want the timer to stop when i go back and the drawing to restart when i visit the second view again.
The methods viewdidLoad
and initWithFrame:
do not work inside the subclass.
awakeFromNib
, viewdidLoad
and initWithFrame
are all called during the initialization phase of the object. If the object is already created, those methods will not be called again. You can force a view to draw itself by using the setNeedsDisplay
method of the view.
精彩评论