gpt4 book ai didi

ios - - UIView 类别中的 awakeFromNib

转载 作者:行者123 更新时间:2023-11-29 01:36:32 27 4
gpt4 key购买 nike

在 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.

参见:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html

关于ios - - UIView 类别中的 awakeFromNib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906581/

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