In a custom iOS Control, I would like to include the layoutSubviews method of the underlying UIView, so I dont have to resize the subviews manually.
For this, I created a structure
Instance as Ptr
SuperClass as Ptr
I have a method
Sub CallSelectorOnSuperSuperClass(extends instance as AppleObject, Selector as ptr)
dim superobject as objc_super
superobject.Instance = instance.id
superobject.SuperClass = class_getSuperclass(instance.superclass)
objc_msgSendSuper_Stret (superobject, Selector)
(In this case I am working on a subclass of UIScrollView. Therefore I go two steps up in the class hierarchy: custom class -> UIScrollView -> UIView. I tried with only one step, but it didnt work too.)
Protected Declare Sub objc_msgSendSuper_stret Lib obj_C (superobject as ObjectiveCRuntime.objc_super, Selector as Ptr)
And I feed this method with NSSelectorFromString (“layoutSubviews”). All the ptrs are set nicely, which means not nil, and I checked the superclass is ok. The text constant obj_c is “/usr/lib/libobjc.dylib”.
It crashes the project with *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[UIView layoutSubviews]: unrecognized selector sent to class 0x13710a8’
and the relevant part of the crashlog is
0 CoreFoundation 0x025a1a14 _exceptionPreprocess + 180
1 libobjc.A.dylib 0x01e62e02 objc_exception_throw + 50
2 CoreFoundation 0x025aac03 +[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x024e86bd forwarding + 1037
4 CoreFoundation 0x025a30de forwarding_prep_1 + 14
5 My iOS App.debug 0x00108a04 ObjectiveCRuntime.$CallSelectorOnSuperSuperClass%%op + 498
6 My iOS App.debug 0x0004c1cf View1.View1.iOSLibScrollView1_Resized%%o<View1.View1>o + 355
Well yes, of course NSObject doesnt know about layoutSubviews. I thought that the super_stret method was meant for problems like this. Obviously I am wrong somewhere but where? Sure, methods are basically anchored in the class, but I am surprised the whole log looks like I try to invoke a class method where I need an instance method. Is there any objC function Ive overseen?