iOS Question [B4X] I need B4XRadioButton <custom view heres>. How to add programmatically? on BCTextEngine

ermales

Member
Licensed User
I am guiding myself in this example https://www.b4x.com/android/forum/t...t-engine-bbcode-parser-rich-text-view.106207/ I want to add a radiobutton but i have problems doing it.

error:
Application_Start
Error occurred on line: 46 (B4XMainPage)
Object was not initialized (UIView)
Stack Trace: (
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 627356
  libobjc.A.dylib      objc_exception_throw + 60
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 983952
  B4i Example          -[B4IObjectWrapper object] + 116
  B4i Example          -[B4XViewWrapper SetLayoutAnimated:::::] + 60
  B4i Example          -[b4i_b4xmainpage _b4xpage_created::] + 1884
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600
  B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300
  B4i Example          -[B4ICommon CallSubDebug4::::] + 860
 B4i Example          -[B4ICommon CallSubDebug2::::] + 284
 B4i Example          -[b4i_b4xpagesmanager _createpageifneeded::] + 984
 B4i Example          -[b4i_b4xpagesmanager _showpage::] + 692
 B4i Example          -[b4i_b4xpagesmanager _addpage:::] + 1216
 B4i Example          -[b4i_b4xpagesmanager _addpageandcreate:::] + 532
 B4i Example          -[b4i_b4xpagesmanager _initialize:::] + 1592
 B4i Example          -[b4i_main _application_start:] + 592
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600
 B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300
 B4i Example          -[B4IShell runMethod:] + 448
 B4i Example          -[B4IShell raiseEventImpl:method:args::] + 2172
 B4i Example          -[B4IShellBI raiseEvent:event:params:] + 1580
 B4i Example          __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 7788
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 14896
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 73544
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 44
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 333824
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 46852
 CoreFoundation       CFRunLoopRunSpecific + 600
 GraphicsServices     GSEventRunModal + 164
 UIKitCore            3ED35565-456D-33CB-B554-6C567FA81585 + 5326408
 UIKitCore            UIApplicationMain + 364
 B4i Example          main + 104
 dyld                 start + 520
)
Application_Active

according to the error I try to initialize it but I have not succeeded, below the code

Code:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Private xui As XUI
End Sub

Public Sub Initialize
    
End Sub

'B4i - don't miss the inline OBJC code in the main module.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("1")
    TextEngine.Initialize(Root)
    BBCodeView1.TextEngine = TextEngine
    Dim btn As Button
    Dim rbtn As B4XRadioButton
    #if B4i
    btn.Initialize("btn", btn.STYLE_SYSTEM)

    #Else If B4J or B4A
    btn.Initialize("btn")
    #End If
    rbtn.Initialize(Me,"rbtn")
    Dim xbtn As B4XView = btn
    Dim xrbtn As B4XView = rbtn.mBase
    If xui.IsB4i Then
        xbtn.SetColorAndBorder(xui.Color_Transparent, 1dip, xui.Color_Black, 2dip)
    End If
    xbtn.Text = "Click!"
    xbtn.SetLayoutAnimated(0, 0, 0, 100dip, 40dip)
'    xrbtn.Text="hola mundo"
'    rbtn.SetLayoutAnimated(0, 0, 0, 100dip, 40dip)
    xrbtn.SetLayoutAnimated(0, 0, 0, 100dip, 40dip)
    
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 200dip, 120dip)
    BBCodeView1.Views.Put("btn", btn)
    BBCodeView1.Views.Put("rbtn", rbtn)
    BBCodeView1.Text = _
$"[Alignment=Center][TextSize=20][b][u]This is the title [FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]
Emoji made of multiple "characters": ?‍? and a flag: [TextSize=30][e=??/][/TextSize]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc fermentum elit vitae nisi faucibus, vitae lacinia turpis mattis.
Lets add a [Color=#ff0000][b]button:[/b][/color] [View=btn Vertical=10/]  and more text here...
We can also add links, for example: [url]https://www.google.com[/url]. You can click on the link. The title will be updated.
Here is a nice logo: [img FileName="logo.png" width=50/]
We can also download an image here: [url="DonManfred's avatar"][img url="https://b4x-4c17.kxcdn.com/android/forum/data/avatars/l/42/42649.jpg?1432374732" width=60 height=60/][/url]
Note that you must explicitly set the dimensions of such images.
Colors:
[list]
[*][Color=#ff0000][b][u]Red[/u][/b][/Color]
[*][Color=#00ff00][b][u color=Magenta]Green[/u][/b][/Color]
[*][Color=#0000ff][b][u color=DarkGray Thickness=3]Blue[/u][/b][/Color]
[/list]
Items:
[list style=ordered]
[*]Item A
[*]Item B
[*]Item C
[/list]
${TableRow("[b]Column 1[/b]", "[b]Column 2[/b]", "[b]Column 3[/b]")}
${TableRow($"[img FileName="logo.png" width=30/]000"$, "100", "200")}
${TableRow($"[color=#ff0000][b]-232[/b][/color]"$, "AAA", "CCC")}
${TableRow($"[color=#ff0000][b]-232[/b][/color]"$, "AAA", "CCC")}
${TableRow($"[color=#ff0000][b]-232[/b][/color]"$, "AAA", "CCC")}
${TableRow($"[color=#ff0000][b]-232[/b][/color]"$, "AAA", "CCC")}
rbtn
"$
End Sub

Sub TableRow(Field1 As String, Field2 As String, Field3 As String) As String
    Return $"[Span MinWidth=33%x Alignment=center]${Field1}[/Span][Span MinWidth=33%x Alignment=center]${Field2}[/Span][Span MinWidth=33%x Alignment=center]${Field3}[/Span]"$
End Sub

Sub btn_Click
    Log("click")
End Sub

Sub BBCodeView1_LinkClicked (URL As String)
    B4XPages.SetTitle(Me, URL)
End Sub

'************ B4i - adds a cancel action to touch events:
#if OBJC
@end
@interface B4IPanelView  (touchcancelled)
@end
@implementation B4IPanelView  (touchcancelled)

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        B4I* bi = [self valueForKey:@"bi"];
        NSString* eventName = [self valueForKey:@"eventName"];
        for (UITouch *u in touches) {
            CGPoint p = [u locationInView:self];
            [bi raiseEvent:self event:eventName params:@[@4, @(p.x), @(p.y)]];
        }
}
#End If
'**************************
 

ermales

Member
Licensed User
Probar:
[código]
BBCodeView1.Views.Put("rbtn", rbtn.mBase)
[/código]

Las clases de vistas personalizadas no son vistas por sí mismas. Debe agregar la vista.

lo hice, ahora tengo otro error

Logs:
 Application_Start
Error en línea: 44 (B4XMainPage)
El objeto no se inicializó (UIView)
Seguimiento de pila: (
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 627356
libobjc. A.dylib objc_exception_throw + 60
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 983952
Ejemplo B4i -[Objeto B4IObjectWrapper] + 116
Ejemplo de B4i -[B4XViewWrapper SetLayoutAnimated:::::] + 60
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600
Ejemplo de B4i +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300
Ejemplo de B4i -[B4IShell runVoidMethod] + 232
Ejemplo de B4i -[B4IShell raiseEventImpl:method:args::] + 1800
Ejemplo de B4i -[B4IShellBI raiseEvent:event:params:] + 1580
Ejemplo de B4i +[Delegado de B4IDebug:::] + 80
Ejemplo B4i -[b4i_b4xmainpage _b4xpage_created::] + 320
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600
Ejemplo de B4i +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300
Ejemplo de B4i -[B4ICommon CallSubDebug4::::] + 860
Ejemplo de B4i -[B4ICommon CallSubDebug2::::] + 284
Ejemplo B4i -[b4i_b4xpagesmanager _createpageifneeded::] + 984
Ejemplo B4i -[b4i_b4xpagesmanager _showpage::] + 692
Ejemplo B4i -[b4i_b4xpagesmanager _addpage:::] + 1216
Ejemplo B4i -[b4i_b4xpagesmanager _addpageandcreate:::] + 532
Ejemplo B4i -[b4i_b4xpagesmanager _initialize:::] + 1592
Ejemplo B4i -[b4i_main _application_start:] + 592
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600
Ejemplo de B4i +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300
Ejemplo de B4i -[B4IShell runMethod:] + 448
Ejemplo de B4i -[B4IShell raiseEventImpl:method:args::] + 2172
Ejemplo de B4i -[B4IShellBI raiseEvent:event:params:] + 1580
Ejemplo de B4i __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 7788
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 14896
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 73544
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 44
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 333824
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 46852
 CoreFoundation       CFRunLoopRunSpecific + 600
 GraphicsServices     GSEventRunModal + 164
 UIKitCore            3ED35565-456D-33CB-B554-6C567FA81585 + 5326408
 UIKitCore            UIApplicationMain + 364
B4i Ejemplo principal + 104
dyld inicio + 520
)
Llame a B4XPages.GetManager.LogEvents = True para habilitar el registro de eventos B4XPages.
Instancia de clase (b4i_b4xradiobutton) publicada.
Application_Active
[/CÓDIGO]
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1654062214177.png


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 120dip, 120dip)
    pnl.LoadLayout("RadioButtons")
    BBCodeView1.Views.Put("RadioButtons", pnl)
    BBCodeView1.Text = $"Please choose one of the following options:
    [view=RadioButtons/]
And more text here..."$
End Sub
 

Attachments

  • Project.zip
    176.1 KB · Views: 204
Upvote 0
Top