Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I created a simple view based project in XCode and the following works for me. I didn't add Facebook to the mix but the UITextField should simulate it. What this does is:</p> <ol> <li><p>Touching the UIButton or shaking the device will toggle editing of the UITextField including showing/hiding the keyboard</p></li> <li><p>The UILabel <code>statusLabel</code> will display the last touch or shake action and then timeout to display the default text.</p></li> </ol> <p>You can create a similar project and copy/paste this in or try to work with your existing app.</p> <p>EDITED TO ADD .H FILE</p> <p>Header:</p> <pre><code>// ShakeShakeShakeViewController.h #import &lt;UIKit/UIKit.h&gt; @interface ShakeShakeShakeViewController : UIViewController { UITextField * _textField; UILabel * _statusLabel; UIButton * _actionButton; } @property (nonatomic, retain) IBOutlet UITextField * textField; @property (nonatomic, retain) IBOutlet UILabel * statusLabel; @property (nonatomic, retain) IBOutlet UIButton * actionButton; - (IBAction)userInvokedActionWithControl:(id)sender; - (void)resetStatusLabel; - (void)toggleTextFieldEditing; @end </code></pre> <p>Source:</p> <pre><code>// ShakeShakeShakeViewController.m #import "ShakeShakeShakeViewController.h" @implementation ShakeShakeShakeViewController @synthesize textField = _textField, statusLabel = _statusLabel, actionButton = _actionButton; - (void)dealloc { self.textField = nil; self.statusLabel = nil; self.actionButton = nil; [super dealloc]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - View lifecycle - (void)viewDidLoad { [self resetStatusLabel]; } - (void)viewDidUnload { [super viewDidUnload]; self.textField = nil; self.statusLabel = nil; self.actionButton = nil; } - (void)viewDidAppear:(BOOL)animated { [self becomeFirstResponder]; } - (IBAction)userInvokedActionWithControl:(id)sender { NSLog(@"Touched"); self.statusLabel.text = @"Touched"; [self toggleTextFieldEditing]; } - (BOOL)canBecomeFirstResponder { return YES; } - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion != UIEventSubtypeMotionShake) return; NSLog(@"Shaking..."); self.statusLabel.text = @"Shaking..."; } - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion != UIEventSubtypeMotionShake) return; NSLog(@"Done shaking..."); self.statusLabel.text = @"Done shaking"; [self toggleTextFieldEditing]; } - (void)toggleTextFieldEditing { if ([self.textField isFirstResponder]) { [self becomeFirstResponder]; } else { [self.textField becomeFirstResponder]; } [self performSelector:@selector(resetStatusLabel) withObject:nil afterDelay:2]; } - (void)resetStatusLabel { self.statusLabel.text = @"Shake me"; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload