1

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 in 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?

4

1 回答 1

1

这只是一个疯狂的猜测,但内存不足的警告可能会导致视图从内存中清除,并且当它重新加载时,视图不再存在,因为如果发生这种情况,viewDidLoad 中没有任何内容可以重新显示它。您可能需要将视图存储在 ivar 中,然后让 viewDidLoad 再次添加它(如果存在)。

你可以通过在模拟器中运行来测试这个理论,然后让它产生一个内存不足的警告,看看这是否会使视图消失。如果当前显示视图,我认为不会发生这种情况,因此请确保当时显示其他视图。

于 2010-01-14T17:20:05.727 回答