Send a msg to a super object?

In a custom iOS Control, I would like to include the layoutSubviews method of the underlying UIView, so I don’t have to resize the subviews manually.
For this, I created a structure

Objc_Super with 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) End Sub

(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 didn’t work too.)

objc_msgSendSuper_stret is

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 doesn’t 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 I’ve overseen?

Never mind. I got it working. I just needed to call one super (I had a msg_sendsuper with a return value before and that caused a different crash, and I did not try to go only one step up in the hierarchy afterwards.).

Well, it doesn’t help in this case. As I tried out before the Scrollview frame itself is resized then, not the contentview frame :wink:
But, anyway: Calling super implementations works.

The problem may be that you are sending the “layoutSubviews:” selector instead of “layoutSubviews” (notice the difference of the colon) and this is why it doesn’t recognize the selector.

Edit: Glad you figured it out.