gpt4 book ai didi

objective-c - 没有子类化 UIView 或 UIViewController : possible to catch if a subview was added?

转载 作者:行者123 更新时间:2023-11-28 20:25:32 26 4
gpt4 key购买 nike

如果将 View 作为 subview 添加到 Controller 的现有 View 中,是否有办法捕获事件或通知?我这里有一个库,我不能子类化,但需要知道是否添加了特定的 subview 来触发自定义操作。有机会吗?

最佳答案

我将尝试为 didAddSubview 方法添加一个类别。

编辑

Category 是子类化的替代方法,因此您可以使用类似的东西:

.h:

  #import <UIkit/UIKit.h>

@interface UIView (AddSubView)

- (void)didAddSubview:(UIView *)view

@end

.m:

@implementation UIView (AddSubView)
- (void)didAddSubview:(UIView *)view
{
[self addSubview: view];

// invoke the method you want to notify the addition of the subview

}
@end

关于objective-c - 没有子类化 UIView 或 UIViewController : possible to catch if a subview was added?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14124810/

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