开发者

Calling UIViews's subviews property increments subview retain count by 1?

开发者 https://www.devze.com 2023-03-16 15:22 出处:网络
I have this code: UIView *superView = [[UIView alloc] init]; UIView *subView = [[UIView alloc] init]; [superView addSubview:subView];

I have this code:

UIView *superView = [[UIView alloc] init];
UIView *subView = [[UIView alloc] init];
[superView addSubview:subView];
[subView release];
NSLog(@"retain before %i", [subView retainCount]);//prints 1
int i = superView.subviews.count ;
NSLog(@"retain after %i", [subView retai开发者_StackOverflow中文版nCount]);//prints 2
i = superView.subviews.count ;
NSLog(@"retain odd %i", [subView retainCount]);//keeps printing 2

Is this an "expected" behavior ?. If so, what is the underlying logic ?

0

精彩评论

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