iOS Code Snippet Input-Dialog

Discussion in 'iOS Code Snippets' started by Filippo, Apr 16, 2015.

  1. Filippo

    Filippo Expert Licensed User

    Hi,

    I extended the code of Erel and turned into a proper input-dialog. :)

    Insert the code into a code-module.
    Code:
    #Region Input-Dialog with Objective C code
    #If OBJC
    - (void)ShowInputDialog:(NSString*)Input :(NSString*)Title :(NSString*)Message :(NSString*)OK :(NSString*)Cancel :(int)KeybardType
    {
      UIAlertView * alert = [[UIAlertView alloc] initWithTitle:Title
        message:Message delegate:self cancelButtonTitle:Cancel otherButtonTitles:OK, nil];
        alert.alertViewStyle = UIAlertViewStylePlainTextInput;

        UITextField * alertTextField = [alert textFieldAtIndex:0];
        alertTextField.keyboardType = KeybardType;
       
        alertTextField.text = Input;
        alert.delegate = self;
        [alert show];
    }
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 1) {
            [self.bi raiseEvent:nil event:@"inputdialog_result:" params:@[[[alertView textFieldAtIndex:0] text]]];
        }
    }
    #End If

    ' InputType:
    ' 0 = UIKeyboardTypeDefault
    ' 1 = UIKeyboardTypeASCIICapable
    ' 2 = UIKeyboardTypeNumbersAndPunctuation
    ' 3 = UIKeyboardTypeURL
    ' 4 = UIKeyboardTypeNumberPad
    ' 5 = UIKeyboardTypePhonePad
    ' 6 = UIKeyboardTypeNamePhonePad
    ' 7 = UIKeyboardTypeEmailAddress
    ' 8 = UIKeyboardTypeDecimalPad
    ' 9 = UIKeyboardTypeTwitter
    '10 = UIKeyboardTypeWebSearch
    '11 = UIKeyboardTypeAlphabet
    '12 = UIKeyboardTypeASCIICapable
    Sub InputDialog(Input As String, Title As String, Message As String, Positive As String, Cancel As String, InputType As Int)
        
    Dim no As NativeObject = Me
        no.RunMethod(
    "ShowInputDialog::::::"Array(Input, Title, Message, Positive, Cancel, InputType))
    End Sub

    Sub InputDialog_Result(Text As String)
        
    Log("Result: " & Text)
        
    Select strInputDialog
            
    Case "1"
                txtUserName.text=Text
            
    Case "2"
                ...
        
    End Select
    End Sub
    #End Region
    Usage:
    Code:
    Sub Process_Globals
      
    Dim strUserName As String
      
    Dim strInputDialog As String
      
    Dim txtUserName As TextField
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
    ...
    ...
        strInputDialog = 
    "1"
        
    InputDialog(strUserName, "Username""Please enter a name""OK""Cancel"0)
    End Sub
     
    MarcoRome, luke2012, MikeH and 6 others like this.
  2. fishwolf

    fishwolf Active Member Licensed User

    i can change font size in this input dialog ?
     
  3. Filippo

    Filippo Expert Licensed User

    I do not know, but maybe you can help Erel.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible to change the font size.

    You can always implement your own custom dialog with a simple panel.
     
  5. Bryanne Vega

    Bryanne Vega Member Licensed User

    What about multiple inputs @Filippo :3
     
  6. Bryanne Vega

    Bryanne Vega Member Licensed User

    Also, why don't you wrap this to a B4i library?
     
  7. jazzzzzzz

    jazzzzzzz Active Member Licensed User

    For getting button event, replace this method in above sample
    Code:
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        NSString *inStr = [NSString stringWithFormat: @
    "%ld", (long)buttonIndex];
        [self.bi raiseEvent:nil 
    event:@"inputdialog_result::" params:@[([[alertView textFieldAtIndex:0] text]),(inStr)]];
    }
     
    Last edited: Jul 5, 2016
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