tom*_*wel 4 runtime objective-c ios
使用class_addMethod代码:
class_addMethod(newClass, @selector(inputAccessoryView), accessoryImp, "@@:");\nRun Code Online (Sandbox Code Playgroud)\n\n该方法中参数“@@:”的含义是什么?
\n\n文档:
\n\n/** \n * Adds a new method to a class with a given name and implementation.\n * \n * @param cls The class to which to add a method.\n * @param name A selector that specifies the name of the method being added.\n * @param imp A function which is the implementation of the new method. The function must take at least two arguments\xe2\x80\x94self and _cmd.\n * @param types An array of characters that describe the types of the arguments to the method. \n * \n * @return YES if the method was added successfully, otherwise NO \n * (for example, the class already contains a method implementation with that name).\n *\n * @note class_addMethod will add an override of a superclass\'s implementation, \n * but will not replace an existing implementation in this class. \n * To change an existing implementation, use method_setImplementation.\n */\nOBJC_EXPORT BOOL class_addMethod(Class cls, SEL name, IMP imp, \n const char *types) \nOBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);\nRun Code Online (Sandbox Code Playgroud)\n
该types参数描述了\n方法的参数和返回类型,如\n中所述class_addMethod:
\n\n\n描述方法参数类型的字符数组。有关可能的值,请参阅Objective-C 运行时编程指南 > 类型编码。由于该函数必须至少采用两个参数 \xe2\x80\x94
\nself和_cmd,因此第二个和第三个字符必须是 \xe2\x80\x9c@:\xe2\x80\x9d (第一个字符是返回类型)。
"@@:"描述了一个方法,返回一个对象\n(类型编码@,在你的情况下:) UIView *,并且除了固定(隐藏)参数self(@对象的类型编码)和(选择器的_cmd类型编码)之外不接受任何参数。:
| 归档时间: |
|
| 查看次数: |
1621 次 |
| 最近记录: |