CS1160:   Introduction to Computer Science I

 

iOS XCode Emulator Tips

 

Flip between Landscape and Portrait Views

 

AppleButton + ->                                AppletButton + <-

apple button + right arrow button              AND       apple button + left arrow button

 

 

Device emulation controlls

  • Rotate Left. Rotates the simulator to the left.

  • Rotate Right. Rotates the simulator to the right.

  • Shake Gesture. Shakes the simulator.

  • Home. Takes the simulator to the Home screen.

  • Lock. Locks the simulator.

  • Simulate Memory Warning. Sends the frontmost app low-memory warnings. For information on how to handle low-memory situations, see “Observing Low-Memory Warnings” in iOS App Programming Guide.

  • Toggle In-Call Status Bar. Toggles the status bar between its normal state and its state when a phone call or FaceTime call is in progress. The status bar is taller in its in-call state than in its normal state. This command shows how your app’s user interface looks when the user launches your app during a call.

  • Simulate Hardware Keyboard. Toggles the software keyboard on an iPad simulator. Turn off the software keyboard to simulate using a keyboard dock or wireless keyboard with an iPad device.

  • TV Out. Opens a window simulating the TV out signal of a device.

  • NO simulation accelerometer or camera hardware.

  • Location is fixed (but, can change in XCode 4.2+ and use GPX files)

 

 

How to get rid of Keyboard after typing in a TextField

  • in Android this is automatic in the emulator....here we have to do some code.

 

STEP 0: Suppose this is xib interface of your app with a Text Field in it

interface with textfield

STEP 1: Augement the Code of the ViewController.h class that contains the TextField(s) -- make it UITextFieldDelegate

//
//  HITest_ViewController.h
//  HiTest
//
//  Created by student on 12/4/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface HITest_ViewController : UIViewController <UITextFieldDelegate> {

    NSString *currentMessage;
IBOutlet UITextField *textField;
IBOutlet UILabel *messageField;
IBOutlet UIButton *change_message_button;
}

- (IBAction)showMessage:(id)sender;

 

//new method to call when Return button hit on TextField this class serves as delegate for
- (BOOL)textFieldShouldReturn:(UITextField *)tf;

@end

 

STEP 2: Alter the ViewController.m to implement the textFieldShouldReturn method as follows

 

//
//  HITest_ViewController.m
//  HiTest
//
//  Created by student on 12/4/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "HITest_ViewController.h"

@interface HITest_ViewController ()

@end

@implementation HITest_ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
textField = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if(self) {
//setup default message
currentMessage = @"Hi 4521";
}
return self;
}

 

//method to handle event when button hit
- (IBAction)showMessage:(id)sender
{

    //get current typed in message
currentMessage = [textField text];

NSLog(@"going to display message %@", currentMessage);

//display new meeage
[messageField setText:currentMessage];
}

 

//method to get rid of keyboard
- (BOOL)textFieldShouldReturn:(UITextField *)tf
{
[tf resignFirstResponder];
NSLog(@"Entering textFieldShouldReturn");
return YES;
}

@end

 

STEP 3: setup the TextField's Delegate to be the FileOwner (the View Controller) --do this in InterfaceBuilder controll.....select the text field and hit right mouse to bring up connections window and drage from delegate to the FileOwner Icon

delegate is FileOwner

© Lynne Grewe