开发者

Dynamically added subview disappears

开发者 https://www.devze.com 2022-12-16 04:55 出处:网络
I have a UIView that gets created and added as a subview dynamically, not in interface builder. Problem is the subview disappears eventually and all that is left on the screen is the objects that are

I have a UIView that gets created and added as a subview dynamically, not in interface builder. Problem is the subview disappears eventually and all that is left on the screen is the objects that are defined i开发者_JAVA技巧n the xib that is being loaded.

It seems to occur once the retainCount of the subview drops from 3 to 2. I'm fairly new to iPhone development and don't fully understand the memory management complexities so I may be missing something obvious. What could be my problem?


This is just a wild guess, but a low memory warning might be causing the view to get purged from memory, and when it's reloaded the view is no longer there because there's nothing in viewDidLoad to redisplay it if this happens. You may need to store the view in an ivar, then have viewDidLoad add it again if it exists.

You could test this theory by running in the simulator, then causing it to generate a low memory warning to see if that makes the view disappear. I don't think this should happen if the view is currently displayed though so make sure some other view is displayed at the time.

0

精彩评论

暂无评论...
验证码 换一张
取 消