简体   繁体   中英

About Interface Builder components release

If I have some objects like UILabel, UIImageView, etc. on my XIB
But I don't using any IBOutlet to connect them
I reference these objects like follow

UILabel *label =  (UILabel *)[[self.view subviews] objectAtIndex:x];
UIImageView *imageView =  (UIImageView *)[[self.view subviews] objectAtIndex:x];

Do I need release this objects?

If you are not retaining this objects you don't has to release them. You only has to release the object that you create

You should release all the object what ever you created. it's good habit.

Otherwise you ll get memory problem.

No. If you don't call retain on it, then you don't have to release it.

However, your approach is very bad. Is any reason that stop your from creating IBOutlet connection? Even use viewWithTag: will do a better job. Because if you add a new view to nib, it is very likely to mess the order and you have to change every hardcoded index value.

除非您自己分配,初始化,保留和复制对象,否则不应释放它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM