ios7 - Can i update value of label by long press on it - iOS -


I write a simple application with Xcode 5 on the iPhone iOS7 device. I have a label that increases with the +/- button, but I want to give the user the option to enter their numbers on this label. How can I do this with a long press identifier? Thank you.

use a UILongPressGestureRecognizer and a UITextView .

Add a UILongPressGstureRecognizer property to your view controller:

  @propertyUILongPressGestureRecognizer * gestureRecognizer;   

You have to see that your view controller corresponds to UITextViewDelegate and UIGestureRecognizerDelegate protocol:

  @interface view controller: UIViewController & lt; UITextViewDelegate, UIGestureRecognizerDelegate & gt;  viewDidLoad  in   

:

  self.textView.editable = NO; Self.textView.delegate = self; Self.gesturerecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget: Self-action: @Selector (TextualGuoder :)]; Self.gesturerecognizer.delegate = self; [Self.textView addGestureRecognizer: self.gr];   

This is the method that you will call upon when the text view is pressed for a long time:

  - (zero) text message langard: (UILongPressGestureRecognizer *) sender {Self.textView.editable = Yes; [Self.textViewFirstResponder]; }   

Apply this method to UIGestureRecognizerDelegate

  - (BOOL) gesture: Indicator: (UIGestureRecognizer *) Gesture Should be identified with synonymsChandler: (UIGestureRecognizer *) Other GestureRecognizer {If (self.gestureRecognizer == gestation provider) {return yes; } no return; }   

When you end the editing of text view

  - (zero) text viewideiding: (UITxviewview) * Text view {self.textView.editable = NO; }   

When you press Return to dismiss the keyboard:

  - (BOOL) TextView: (UITextView *) textView should changeChangeInRange: (NSR ) Limit replacement text: (NSString *) Text {if ([text isEqualToString: @ "\ n"]) [textView resignFirstResponder]; // or [textView end editing: yes] return yes; }    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -