I have a text box in which I wanted the user to enter only numbers. I have introduced a numeric keypad. But if someone puts my application in the background and copies some character string from another application and returns to my application and pastes it, it successfully inserts the contents of the string into my numeric text box. How can I limit this scenario?
@theChrisKent is close, but there is a slightly better way. Use the delegate method -textView:shouldChangeTextInRange:replacementText:. Make sure it replacementTextcontains any non-numbers, and if so, return it NO.
-textView:shouldChangeTextInRange:replacementText:
replacementText
NO
, : , , , UITextView
UITextView (, ):
UITextView
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(paste:) return NO; return [super canPerformAction:action withSender:sender]; }
UITextViewDelegate textViewDidChange: , . , . : http://developer.apple.com/library/ios/documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html#//apple_ref/occ/intfm/UITextViewDelegate/textViewDidChange:
UITextViewDelegate
textViewDidChange:
Source: https://habr.com/ru/post/1791325/More articles:How to get rid of System.ServiceModel.ClientBase ? - idisposableWhat is the best way to find out the limitations of an IBMi DB2400 table from a java program? - javaHow to write a hash code for a tree-like data structure based on the location of an item in a tree? - c #how to transfer data to a JSON server using cURL with POST - jsonGoogle V3 Maps API: XML Parsing - javascriptSQL server - удалять строки, в которых несколько столбцов имеют нулевое или нулевое значение - sqlTrying to use jQuery.addClass method with navigation - javascriptстрока каретки возвращает из сериализации xml в F # - carriage-returnSQL ... How to update rows with data from other rows in one table? - sqlUnderstanding MVC Models - asp.net-mvcAll Articles