iOS Question Composing Custom Views inside each other - is it possible?

Tom Phillips

Member
Licensed User
Is it possible to programmatically instantiate a custom view within another custom view? For instance, I have created a modal/dialog custom view that I would like to embed a CustomListView inside. The modal view is added via the designer, but the CustomListView ideally will be instantiated and managed by the modal. After initializing the CustomListView and attempting to attach it to a child view of my custom modal, I receive an unrecognized selector error.

Operation that causes error:
B4X:
UserListView.Initialize(ModalBackgroundPanel, "UserListView")
ModalForegroundPanel.AddView(UserListView, 0, 0, 100, 100)

Error message:
B4X:
Error occurred on line: 62 (UserPicker)
-[b4i_customlistview superview]: unrecognized selector sent to instance 0x1c00b3e60
Stack Trace: (
  CoreFoundation       <redacted> + 148
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 1380
  CoreFoundation       _CF_forwarding_prep_0 + 92
  UIKit                <redacted> + 148
  BirdID iOS           -[B4IPanelWrapper AddView:::::] + 132
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  BirdID iOS           +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 BirdID iOS           -[B4IShell runVoidMethod] + 232
 BirdID iOS           -[B4IShell raiseEventImpl:method:args::] + 1416
 BirdID iOS           -[B4IShellBI raiseEvent:event:params:] + 1408
 BirdID iOS           __24-[B4ITimer startTicking]_block_invoke + 332
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 428
 libdispatch.dylib    <redacted> + 1588
 libdispatch.dylib    <redacted> + 720
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 2012
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 100
 UIKit                UIApplicationMain + 208
 BirdID iOS           main + 124
 libdyld.dylib        <redacted> + 4
)

If composition of custom views is possible, an example would be greatly appreciated. Thanks for reading!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Check this library for custom dialogs: https://www.b4x.com/android/forum/threads/custom-dialogs-with-icustomdialog-library.83526/#content

The custom view class instance is not a view by itself.
CustomListView.GetBase will return the base panel that holds the other views. However you should instead create a layout file with the CLV anchored to all sides and load it with Panel.LoadLayout.

There is one limitation. You cannot load a layout from inside DesignerCreateView unless you add Sleep(0) before. By calling Sleep(0) you are causing the second layout to be loaded after the first one completed.
 
Upvote 0
Top