Skip to content

Instantly share code, notes, and snippets.

@bmulholland
Created October 23, 2012 20:28
Show Gist options
  • Save bmulholland/3941325 to your computer and use it in GitHub Desktop.
Save bmulholland/3941325 to your computer and use it in GitHub Desktop.
iOS6 Keyboard Weirdness
// AppDelegate.m
//
// AppDelegate.m
// Test
//
// Created by Brendan Mulholland on 2012-10-23.
// Copyright (c) 2012 Brendan Mulholland. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Build views
ViewController *topViewController = [[ViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:topViewController];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (UITableViewController*) getNextStep {
return [ViewController alloc];
}
@end
// ViewController.m
//
// ViewController.m
// Test
//
// Created by Brendan Mulholland on 2012-10-23.
// Copyright (c) 2012 Brendan Mulholland. All rights reserved.
//
#import "ViewController.h"
#import "AppDelegate.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize field = _field;
- (id)init {
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
// Disable scrolling, since these screens have one entry and scrolling introduces a bug
self.tableView.scrollEnabled = NO;
self.title = @"test page 1";
self.navigationItem.title = @"Title";
UIBarButtonItem* nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Title"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(nextStep)];
self.navigationItem.rightBarButtonItem = nextButton;
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
static NSString *CellIdentifier = @"Cell";
self.cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (self.cell == nil) {
self.cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
self.cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
CGRect fieldFrame = CGRectMake(0, 0, self.cell.frame.size.width - 20, 44);
self.field = [[UITextField alloc] initWithFrame:fieldFrame];
self.field.backgroundColor = [UIColor colorWithHue:0 saturation:1 brightness:0.3 alpha:0.03];
self.field.font = [UIFont boldSystemFontOfSize:36];
self.field.textAlignment = UITextAlignmentCenter;
self.field.keyboardType = UIKeyboardTypeNumberPad;
[self.field becomeFirstResponder];
[self.field setDelegate:self]; // For formatting
[self.field addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
self.cell.accessoryView = self.field;
self.field.text = @"mytext";
}
- (void)nextStep
{
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
UIViewController* nextController = [[appDelegate getNextStep] init];
[self.navigationController pushViewController:nextController animated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 78;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment