Skip to content

Instantly share code, notes, and snippets.

@jon
Created February 9, 2010 22:15
Show Gist options
  • Save jon/299752 to your computer and use it in GitHub Desktop.
Save jon/299752 to your computer and use it in GitHub Desktop.
A table view containing a single editable text field
//
// BPTextFieldViewController.h
//
// Created by Jon Olson on 10/2/09.
// Copyright 2009 Ballistic Pigeon, LLC. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface BPTextFieldViewController : UITableViewController {
UITableViewCell *cell;
UITextField *textField;
}
@property (readonly) UITextField *textField;
@end
//
// BPTextFieldViewController.m
//
// Created by Jon Olson on 10/2/09.
// Copyright 2009 Ballistic Pigeon, LLC. All rights reserved.
//
#import "BPTextFieldViewController.h"
@implementation BPTextFieldViewController
- (UITextField *)textField {
self.view;
return textField;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.allowsSelection = NO;
textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 6, self.tableView.frame.size.width - 40, 31)];
textField.borderStyle = UITextBorderStyleNone;
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
textField.font = [UIFont systemFontOfSize:15.0];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell.contentView addSubview:textField];
}
- (void)viewDidUnload {
[textField release];
textField = nil;
[cell release];
cell = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 45.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return cell;
}
- (void)dealloc {
[textField release];
[cell release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment