0

I am drawing with multiple colors by dragging fingers on the iPhone app but when I minimize the app and then maximizes, I am losing all my drawing as it calls the drawrect method. I don't know from where this method is being called but I am not able to see any solution to this problem. Mainly it is happening when I am running many apps on the device. I think the iOS deletes all the data in the buffer in order to prevent low performance of the iPhone. What is the solution to this issue? And why it is losing the drawing? Please help! I didn't find any solution of this problem.

Developer
  • 6,375
  • 12
  • 58
  • 92

3 Answers3

1

Because your view is unloaded in the background , and when you are back to the foreground , the view will be recreat , so it will redraw.

When you enter background , if the device memory is low , Apple will unload the background app`s view(even close your app) , to enlarge the memory for the current running app. Your view is unloaded , when you be back to foreground , the view will recreat by the "data" , so make sure do not hold the "data" in the view.

And maybe in IOS6 , Apple modify the mechanism

Guo Luchuan
  • 4,729
  • 25
  • 33
1

I am losing all my drawing as it calls the drawrect method.

From your Question, it seems as if you are not drawing in your drawRect method, drawrect method is called every time your view is updated / loaded. So when you enter from background drawrect method is called. If you are not handling in your drawing mechanism in drawrect method, you loose all data.

Apple States that

The default implementation of this method does nothing. Subclasses that use native drawing technologies (such as Core Graphics and UIKit) to draw their view’s content should override this method and implement their drawing code there. You do not need to override this method if your view sets its content in other ways. For example, you do not need to override this method if your view just displays a background color or if your view sets its content directly using the underlying layer object. Similarly, you should not override this method if your view uses OpenGL ES to do its drawing.

If you are handling it other ways then you need to handle that after your view is drawn on in viewwillAppear.

Else there can be memory reason, since if you get memory warning, ViewDidLoad is called where you generally initialise data.

DivineDesert
  • 6,924
  • 1
  • 29
  • 61
0

The framework will call drawRect as needed, it is your responsibilty to draw the view when it is called. You should be storing whatever state you need from the users actions in order to redraw the view whenever drawRect is called.

Gary
  • 5,642
  • 1
  • 21
  • 41