在 UIView 类别的 -awakeFromNib 方法中编写代码是否安全。
UIView+XXXXXX.m
@implementation UIView (XXXXXX)
- (void) awakeFromNib {
/* some code here */
}
@结束
最佳答案
该行为未定义,因此我认为它不安全。
来自 Apple 文档:
If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime. This is less likely to be an issue if you’re using categories with your own classes, but can cause problems when using categories to add methods to standard Cocoa or Cocoa Touch classes.
参见:
关于ios - - UIView 类别中的 awakeFromNib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906581/