iOS Question xCustomListView problem [closed for now]

Didier9

Well-Known Member
Licensed User
Longtime User
I am trying to add a CustomListView to a B4i project.

I am getting this error as soon as Page1_Resize() completes:

B4X:
Application_Start
Error occurred on line: 150 (CustomListView)
Object was not initialized (UILabel)
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  LightController      -[B4IObjectWrapper object] + 152
  LightController      -[B4ILabelWrapper TextAlignment] + 40
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 284
  LightController      +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  LightController      -[B4IShell runMethod:] + 448
  LightController      -[B4IShell raiseEventImpl:method:args::] + 1640
 LightController      -[B4IShellBI raiseEvent:event:params:] + 1560
 LightController      +[B4IDebug delegate:::] + 80
 LightController      -[b4i_customlistview _createlabel::] + 432
 LightController      -[b4i_customlistview _insertattextitem::::] + 1304
 LightController      -[b4i_customlistview _addtextitem:::] + 744
 LightController      -[b4i_main _pagemain_resize::] + 5744
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 284
 LightController      +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 LightController      -[B4IShell runMethod:] + 448
 LightController      -[B4IShell raiseEventImpl:method:args::] + 2164
 LightController      -[B4IShellBI raiseEvent:event:params:] + 1560
 LightController      +[B4IObjectWrapper raiseEvent:::] + 300
 LightController      __30-[B4IPanelView layoutSubviews]_block_invoke + 900
 libdispatch.dylib    <redacted> + 24
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1012
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 2272
 CoreFoundation       CFRunLoopRunSpecific + 552
 GraphicsServices     GSEventRunModal + 100
 UIKit                UIApplicationMain + 236
 LightController      main + 124
 libdyld.dylib        <redacted> + 4
)

The offending line is this:
B4X:
Private Sub CreateLabel(txt As String) As B4XView
    [...]
    lbl.TextAlignment = DesignerLabel.TextAlignment
    [...]
End Sub
called withing a function named CreateLabel()
It looks like DesignerLabel is uninitialized when that line is executed.

However, DesignerLabel is defined in a function named DesignerCreateView() which apparently is never called:
B4X:
Public Sub DesignerCreateView (Base As Object, Lbl As     DesignerLabel = Lbl
    [...]
    DesignerLabel = Lbl
    [...]
End Sub

I have attached the project using this code.
Thanks in advance for any help...
 

Attachments

  • LightController.zip
    7.7 KB · Views: 322

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. The first step is to remove CustomListView module and add are a reference to the internal xCustomListView library.

2. You need to add CustomListView with the visual designer.

3. Your PageMain_Resize is wrong. The Resize event can be called many times. You should never add views in that sub. You should use the visual designer instead.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Thank you Erel, I will try 1 and 2 tonight.

The reason I added the views in code is because there may be a variable number of controls per page, depending on screen physical size (at the moment, I am working with an iPad Mini Retina and an iPhone 6 plus), but I only know the screen size in the Resize event, so on smaller devices I may need multiple pages. I guess the solution is to declare all the views I might need in Application_Start, and locate them (and turn off those I do not need) in the Resize event?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The reason I added the views in code is because there may be a variable number of controls per page, depending on screen physical size (at the moment, I am working with an iPad Mini Retina and an iPhone 6 plus), but I only know the screen size in the Resize event, so on smaller devices I may need multiple pages. I guess the solution is to declare all the views I might need in Application_Start, and locate them (and turn off those I do not need) in the Resize event?
No. The solution is to correctly use the visual designer.

Watch the visual designer and B4i/B4J - Resize event tutorials: https://www.b4x.com/etp.html
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
This is on hold at the moment, I have solved my issue some other way, but I will get back to this later as I will need the CustomListView in the next phase of my project.
 
Upvote 0
Top