iOS Question TextField and Context Menu

Discussion in 'iOS Questions' started by Semen Matusovskiy, Apr 11, 2019.

  1. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Hi, guys --

    I want to prevent Copy/Paste/Select menu for TextField (not TextView).

    Stackoverflow talks that it's possible to subclass control and to use callback function canPerformAction.
    But how to do the same in B4I ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Full example:
    Code:
    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.Title = 
    "Page 1"
       Page1.RootPanel.Color = 
    Colors.White
       NavControl.ShowPage(Page1)
       
    Dim tf As TextField = CreateTextField
       Page1.RootPanel.AddView(tf, 
    10dip10dip200dip50dip)
    End Sub

    Sub CreateTextField As TextField
       
    Dim no As NativeObject
       no = no.Initialize(
    "MyTextField").RunMethod("new"Null)
       
    Dim tf As TextField
       tf = no
       tf.BorderStyle = tf.STYLE_ROUNDEDRECT
       
    Return tf
    End Sub


    #if OBJC
    @end
    @interface MyTextField : UITextField
    @end
    @implementation MyTextField
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        return NO;
    }
    #End If
    Note that the events will not work with this text field. It is possible to add them with a bit more work.
     
  3. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Thanx, Erel. I replaced "return no;" to

    Code:
    if (action == @selector(cut:))          return NO;
    if (action == @selector(copy:))         return NO;
    if (action == @selector(paste:))        return NO;
    if (action == @selector(delete:))       return NO; 
    if (action == @selector(select:))       return NO;   
    if (action == @selector(selectAll:))    return NO;
    return [super canPerformAction:action withSender:sender];
    Alone, what I see during LongClick is a magnifier. Ok. But what about events ? Or maybe there is another solution like in Android ? (if I remember correctly it was enough to return true in long click event)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Erel --

    I tried
    Code:
    Sub TextField1_BeginEdit As Boolean
        textField1.UserInteractionEnabled = 
    False  
        
    Return True      
    End Sub

    Sub TextField1_EndEdit
        textField1.UserInteractionEnabled = 
    True
    End Sub
    It "works", but obviously not like I want.

    My real wish is to make LongClick equal to regular Click for all GUI elements.
    Maybe to change something in system settings ?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    There is no such setting.
     
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