ios - - UIView 类别中的 awakeFromNib

标签 ios uiview objective-c-category awakefromnib

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

相关文章:

ios - 将一个字符串插入另一个字符串

ios - 苹果 map 上的简单标记聚类

ios - Objective -C 类问题

ios - 防止自定义类被类别更改

ios - 如何在 Swift 中将文本 (String) 转换为图像 (UIImage)?

ios - RTC 报告和 pancake.apple.com 错误

ios - 在 UIControl/可旋转 View 中获取 UIButton 的点击事件

ios - 在另一个 XIB 中指定类时,如何使用 Custom View.xib 加载自定义 View ?

swift - tableView 在 UIView 内无法正确滚动

ios - 如何在 iOS 中列出 uiviewcontroller 中的所有 subview ?