iOS Question how to make IME.SetCustomFilter in IOS (solved)

jose luis gudino

Active Member
Licensed User
Longtime User
Hi everyone, how can I do this android function on ios?
thanks in advance

B4X:
        Dim poTxt3 As EditText
        poTxt3 = B4XFloatTextField_cedula.TextField ' view is B4XFloatTextField and the .TextField property is B4XView not EditText
        IME.SetCustomFilter(poTxt3, poTxt3.INPUT_TYPE_TEXT, "0123456789AEae")
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private TextField1 As B4XView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
    
    'replace the standard delegate with our own:
    Dim no As NativeObject = TextField1
    Dim del As NativeObject
    del = del.Initialize("MyTextFieldDelegate").RunMethod("new", Null)
    del.SetField("prev", no.GetField("delegate"))
    no.SetField("delegate", del)
End Sub

Private Sub TextField1_ShouldReplace(NewText As String) As Boolean
    For i = 0 To NewText.Length - 1
        Dim c As String = NewText.CharAt(i)
        If "0123456789AEae".IndexOf(c) = -1 Then Return False
    Next
    Return True
    
End Sub

Sub TextField1_EnterPressed
    Log("enter pressed")
End Sub

#if OBJC
@end
@interface MyTextFieldDelegate:NSObject <UITextFieldDelegate>
@property (nonatomic) NSObject<UITextFieldDelegate>* prev;
@end
@implementation MyTextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
  return ((NSNumber*)[B4IObjectWrapper raiseEvent:textField :@"_shouldreplace:" :@[newText]]).boolValue;
}

- (BOOL)textFieldShouldClear:(UITextField *)textField {
   return [_prev textFieldShouldClear:textField];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  return [_prev textFieldShouldReturn:textField];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField {
  [_prev textFieldDidBeginEditing:textField];
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
   [_prev textFieldDidEndEditing:textField];
}
#End If
 
Upvote 0
Top