iOS Question Disable Textfield Copy+Paste which is loaded from Layout

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to disable copy+paste for a textfield.

I have came across the following code:
B4X:
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, 10dip, 10dip, 200dip, 50dip)
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

The above code works, but it adds the textfield when the page as it's adding the view at runtime.

For my project, I am loading a layout to the page which has the textfield in it and I am trying to make it so that the textfield from my layout can't have the copy+paste.

Is there a way I disable the copy+paste function of the textfield (textfield which is created from the layout) ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
Maybe this will help?
I saw that thread but it's for a TextView and not TextField.

I tried it anyway but it didn't work.
It caused an error - [<UITextField 0x16203ba00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key selectable.
 
Upvote 0
Top