# Send a msg to a super object?

**URL:** <https://forum.xojo.com/t/send-a-msg-to-a-super-object/29767>\
**Category:** iOS\
**Created:** [February 15, 2016, 3:01pm UTC](https://forum.xojo.com/t/send-a-msg-to-a-super-object/29767 "2016-02-15T15:01:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [February 15, 2016, 3:01pm UTC](https://forum.xojo.com/t/send-a-msg-to-a-super-object/29767/1 "2016-02-15T15:01:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [February 15, 2016, 3:08pm UTC](https://forum.xojo.com/t/send-a-msg-to-a-super-object/29767/2 "2016-02-15T15:08:30Z")

</div>

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 😉  
But, anyway: Calling super implementations works.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [February 15, 2016, 3:13pm UTC](https://forum.xojo.com/t/send-a-msg-to-a-super-object/29767/3 "2016-02-15T15:13:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:11pm UTC](https://forum.xojo.com/t/send-a-msg-to-a-super-object/29767/4 "2020-10-29T18:11:26Z")

</div>


