当从层次结构中删除视图时,是否会调用willMoveToSuperview(使用nil)? [英] Is willMoveToSuperview called (with nil) when removing a view from a hierarchy?

查看:263
本文介绍了当从层次结构中删除视图时,是否会调用willMoveToSuperview(使用nil)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在 UIView 子类中实现 willMoveToSuperview ,则会保证被调用(<$ c $在您的视图中调用 removeFromSuperview 时,

$ <$>

$ b newSuperview 参数可以 nil ,并且称为超看更改,但我不确定是否可以解释这意味着当视图从其超级视图中删除时,即使没有移动到不同的超级视图,它将被调用。

解决方案

每当视图接收到 removeFromSuperview ,并且视图的superview不是nil, [self willMoveToSuperview:nil]


If you implement willMoveToSuperview on a UIView subclass, is it guaranteed to be called (with nil) when removeFromSuperview is called on your view?

The docs say that the newSuperview parameter may be nil and that it's called "whenever the superview changes" but I'm not sure if I can interpret this to mean it will be called when the view is removed from its superview even when not being moved to a different superview.

解决方案

Whenever a view receives removeFromSuperview, and the view's superview was not already nil, the view will always do [self willMoveToSuperview:nil].

这篇关于当从层次结构中删除视图时,是否会调用willMoveToSuperview(使用nil)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆