iOS Question Call B4i sub from inline OBJC

Discussion in 'iOS Questions' started by narek adonts, Apr 2, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    How can I call b4i sub from inline Objective C code (event,...)

    Narek
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Here:
    Code:
    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Nav.ShowPage(Page1)
       
    Dim no As NativeObject = Me
       no.RunMethod(
    "methodThatRaiseEvent"Null)
    End Sub

    Sub Some_Sub(x As Int)
       
    Log(x)
    End Sub

    #If OBJC
    - (void)methodThatRaiseEvent {
       [self.bi raiseEvent:nil event:@"some_sub:" params:@[@10]];
    }
    #End If
    Note that the sub name in the raiseEvent call must be lower cased.
     
    Derek Johnson likes this.
  3. narek adonts

    narek adonts Well-Known Member Licensed User

  4. narek adonts

    narek adonts Well-Known Member Licensed User

    how pass an NSArray with raiseevent

    [self.bi raiseEvent:nil event:mad:"some_sub:" params:mad:[(NSArray*)myarray]];

    it doesnt work this way
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    B4IList* lst = [B4IList new];
    lst.object = myArray;
    Now pass the list.
     
  6. Derek Johnson

    Derek Johnson Active Member Licensed User

    I noticed that when I tried this example that I got this warning in the log:

    Could you tell me please, is there some declaration needed to get rid of this warning?
     
  7. narek adonts

    narek adonts Well-Known Member Licensed User

    Are you using the same code? Or you modified it? If yes then please post your code
     
  8. Derek Johnson

    Derek Johnson Active Member Licensed User

    Here's the actual code and the responses in the log:

    Code:
    Sub Button2_Click
        
    log("Clicked Me")
        
    Try
             
    Dim NativeMe As NativeObject = Me
             NativeMe.RunMethod(
    "test:"Array (True))
        
    Catch
            rlog(
    "Last exception:" & LastException.Description)
        
    End Try
    End Sub

    #If OBJC

    - (void) test: (bool) on {
       NSLog(@"this is a message");
       [self.bi raiseEvent:nil event:@"olog:" params:@[@"Testing.."]];
    }

    #End If

    Sub olog(msg As String)
        
    Log(msg)
        TextView1.Text=TextView1.Text & msg  & 
    CRLF
    End Sub
    This is the log;

     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Replace raiseEvent with raiseUIEvent.
     
    Derek Johnson likes this.
  10. wineos

    wineos Member Licensed User

    Code:
    [self.bi raiseEvent:nil event:@"some_sub:" params:@[@10]];
    If I want to call an event without parameter, how to change the above code?

    Thank you.
     
  11. narek adonts

    narek adonts Well-Known Member Licensed User

    Code:
    [self.bi raiseEvent:nil event:mad:"some_sub" params:mad:[]];
     
    wineos likes this.
  12. wineos

    wineos Member Licensed User

    Thanks Narek,

    May I ask once more: If I want to call an event with more than 1 parameter, then how to write it?

    Thank you.
     
  13. narek adonts

    narek adonts Well-Known Member Licensed User

    Code:
    [self.bi raiseEvent:nil event:@"some_sub:::" params:@[(param1),(param2),(param3)]];
     
    wineos likes this.
  14. wineos

    wineos Member Licensed User

    Thank you so much, Narek.:)
     
  15. wineos

    wineos Member Licensed User

    Another question.

    Code:
    [self.bi raiseEvent:nil event:@"some_sub:" params:@[@10]];
    I change the parameter to 1, i.e.

    Code:
    [self.bi raiseEvent:nil event:@"some_sub:" params:@[@1]];
    When the code run to

    Code:
    Sub Some_Sub(x As Int)
    the system prompted error, saying that it is not an array. But when I change the parameter to 10, it works.

    Anyone can help?

    Thank you.
     
  16. narek adonts

    narek adonts Well-Known Member Licensed User

    Strange. Try this

    Code:
    [self.bi raiseEvent:nil event:@"some_sub:" params:@[(float)(1.0)]];
     
    wineos likes this.
  17. wineos

    wineos Member Licensed User

    Thank you Narek, I solve it, just like what you did.

    Code:
    [self.bi raiseEvent:nil event:@"some_sub:" params:@[@((int)1)]];
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice