iOS Question Input Accessory Views

Discussion in 'iOS Questions' started by narek adonts, Feb 21, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use NativeObject to set the accessory view. In this example it is a button:
    Code:
    Dim b As Button
    b.Initialize(
    "b", b.STYLE_SYSTEM)
    b.Text = 
    "Click me"
    b.Width = 
    100
    b.Height = 
    50
    Dim no As NativeObject = TextField1
    no.SetField(
    "inputAccessoryView", b)
    You can also add a Panel with more views.
     
  3. Darren69

    Darren69 Member Licensed User

    Hello Erel,

    How do I use the above code? all I want to do is add one button above the keyboard! Silly question I know but just wait until I hit you up with the push notifications one ;)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Complete example:
    Code:
    Sub Process_Globals
       
    Public App As Application
       
    Public NavControl As NavigationController
       
    Private Page1 As Page
       
    Dim tf As TextField
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.Title = 
    "Page 1"
       Page1.RootPanel.Color = 
    Colors.White
       NavControl.ShowPage(Page1)
       tf.Initialize(
    "tf")
       Page1.RootPanel.AddView(tf, 
    00200100)
       
    Dim b As Button
       b.Initialize(
    "b", b.STYLE_SYSTEM)
       b.Text = 
    "Hide keyboard"
       b.Width = 
    100
       b.Height = 
    50
       AddViewToKeyboard(tf, b)
    End Sub

    Sub b_Click
       Page1.ResignFocus
    End Sub

    Sub AddViewToKeyboard(TextField1 As TextField, View1 As View)
       
    Dim no As NativeObject = TextField1
       no.SetField(
    "inputAccessoryView", View1)
    End Sub
     
    Ohanian, MikeH and Brian Robinson like this.
  5. Darren69

    Darren69 Member Licensed User

    Thanks for this Erel, is there a way to make this work with a numeric numberpad?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Yes. There is no relation between the type of keyboard and the accessory view. Just set the KeyboardType property (by code or with the designer).
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Please post the relevant code and the error you got.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    It crashes the app without any error in the logs?
     
    susu likes this.
  9. Arf

    Arf Active Member Licensed User

    I've added this to my code, all compiles fine but I can't see any change to the keyboard. My code is below:
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Private pg As Page
        
    Private sb As StringBuilder
        
    Private serNumber As Label
        
    Private Done As Button
        
    Private NumEntryBox As TextField
        
    Private serNumber2 As Label
        
    Private serNumber3 As Label
        
    Dim tf As TextField

    End Sub

    Public Sub Show
        sb.Initialize
       
        
    If pg.IsInitialized = False Then
            pg.Initialize(
    "pg")
            pg.RootPanel.LoadLayout(
    "sNumberAsk")
            pg.HideBackButton = 
    True '<-- don't want to allow the user to return to the login screen
        End If   
       
        Main.NavControl.ShowPage(pg)
       
        
    Dim b As Button
        b.Initialize(
    "b", b.STYLE_SYSTEM)
        b.Text = 
    "DONE"
        b.Width = 
    100
        b.Height = 
    50
        tf.Initialize(
    "tf")
        AddViewToKeyboard(tf, b)
      
        serNumber.Text = 
    "Please enter your serial number in the box below:"
        serNumber.Visible = 
    True
        NumEntryBox.Enabled = 
    True
        NumEntryBox.Visible = 
    True
        Done.Visible = 
    True
    End Sub

    Sub b_Click
       NumEntryBox_EnterPressed
    End Sub

    Sub AddViewToKeyboard(TextField1 As TextField, View1 As View)
       
    Dim no As NativeObject = TextField1
       no.SetField(
    "inputAccessoryView", View1)
    End Sub
     
  10. Arf

    Arf Active Member Licensed User

    I am getting the following in the Logs window though:
    Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad; using 563160167_Portrait_iPhone-Simple-Pad_Default
     
  11. Arf

    Arf Active Member Licensed User

    Ah I got it working, needed to use NumEntryBox as the TextField for AddViewToKeyboard, not tf.
     
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