
我想通过类似的类别向UIbutton类添加一个新的自定义UIbuttonType:
enum { UIbuttonTypeMatteWhitebordered = 0x100};@interface UIbutton (Custom)+ (ID)buttonWithType:(UIbuttonType)buttonType;@end + (ID)buttonWithType:(UIbuttonType)buttonType { return [super buttonWithType:buttonType];} 上面的代码无效,因为super在此上下文中引用了UIControl.
解决方法 不,当您使用类别来扩充类的功能时,这是不可能的,您没有扩展类,实际上完全覆盖现有方法,您完全失去了原始方法.像风一样.如果您创建UIbutton的子类,那么这是完全可能的:
enum { UIbuttonTypeMatteWhitebordered = 0x100};@interface MyCustombutton : UIbutton {}@end@implementation MyCustombutton + (ID)buttonWithType:(UIbuttonType)buttonType { return [super buttonWithType:buttonType]; //super here refers to UIbutton}@end @H_419_39@ 总结 以上是内存溢出为你收集整理的objective-c – 在重写类方法中调用super全部内容,希望文章能够帮你解决objective-c – 在重写类方法中调用super所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)