tags:

views:

90

answers:

1

Hi,

I created a UIView and a UILabel outlet for the XIB. In the first load is fine then I execute the removeFromSuperview to remove that UIView and call again the addsub to show that UIView again. But when I tried to access again the UILabel like the setText method then the app will crash. Do you think its about removeFromSuperview?

Thanks sasayins

+1  A: 

removeFromSuperview releases UIView. If the retainCount of the UIView hit zero, then it is dealloc'ed and it releases the children of the UIView. If UILabel is on UIView, it too is released. The UIView has to be reloaded before you call addView. You have to load it manually.

Try calling

[[NSBundle mainBundle] loadNibNamed:@"name of your XIB file" owner:self options:nil];

before you call addView. You also should be able to set the UILabel, before or after addView, if you call loadNibNamed.

Of course your problem could be something else, especially if your UIView is being retained.

Try running the Xcode debugger and step through the code.

mahboudz
Yeah my UIView is retained in @property. And I traced the crash when I called the setText of the IBOutlet UILabel. And its weird that the IBOutlet UILabel is not nil. Thanks
sasayins