Sw and而超级
我正尝试调用canPerformAction:withSender:方法为UIResponder及其所有子类重写此方法。
我这样做是通过将原始实现存储在按类名称键入的字典中; 并在调用原始实现之前,在实现的debugging版本中查找字典。
这似乎在某些情况下可以正常工作,但在原始实现调用super时失败。 然后我的方法不断地被调用,程序进入无限recursion。
这里有什么可能是错的?
在调整之后 – -original
与 – -original
:
-(void)custom { [self custom]; // calls -original } -(void)original { [self original]; // calls -custom }
说,如果你在超类中调用了方法,objc_msgSendSuper也会这样做:为自定义调用原始的,反之亦然。
-(void)custom { [self original]; // calls -custom, makes recursion } -(void)original { [self custom]; // calls -original, makes recursion }