gpt4 book ai didi

iphone - 是removeFromSuperview释放了对象吗?

转载 作者:行者123 更新时间:2023-12-03 21:18:11 25 4
gpt4 key购买 nike

我正在使用 removeFromSuperview 从其 super View 中删除 View 。我还在该对象上的 removeFromSuperview 之后使用 release ,有时它工作正常,但有时访问权限很差。

removeFromSuperview 是否也对对象调用 release

最佳答案

是的,removeFromSuperview也会释放 View 。

将 View 添加到其 super View 后,您需要释放它。

CGRect frame; // let's assume you already have defined frame and superview
UIView *superview;

UIView *subview = [[UIView alloc] initWithFrame:frame];
[superview addSubview:subview];
[subview release];

或者在创建 View 时使用autorelease

UIView *subview = [[[UIView alloc] initWithFrame:frame] autorelease];
[superview addSubview:subview];

在这两种情况下,您都不需要在调用 removeFromSuperview 后调用 release

关于iphone - 是removeFromSuperview释放了对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8366380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com