Created
March 2, 2012 17:39
-
-
Save jeksys/1959902 to your computer and use it in GitHub Desktop.
TextEditCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UITableViewCellEnterText : UITableViewCell<UITextFieldDelegate>{ | |
UITextField *textField; | |
} | |
@property (nonatomic, retain) NSMutableDictionary *Value; | |
@property (nonatomic, readonly) NSString *StringValue; | |
@property (nonatomic, retain) UITextField *textField; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UITableViewCellEnterText.h" | |
@implementation UITableViewCellEnterText | |
@synthesize Value; | |
@synthesize StringValue; | |
@synthesize textField = textField; | |
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | |
{ | |
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | |
if (self) { | |
textField = [[UITextField alloc] initWithFrame:CGRectZero]; | |
[self addSubview:textField]; | |
textField.borderStyle = UITextBorderStyleNone; | |
NSString *fontName = @"HelveticaNeue-Medium"; | |
textField.font = [UIFont fontWithName:fontName size:20]; | |
textField.returnKeyType = UIReturnKeyDone; | |
textField.delegate = self; | |
textField.backgroundColor = [UIColor clearColor]; | |
textField.autocorrectionType = UITextAutocorrectionTypeNo; | |
[textField setUserInteractionEnabled:NO]; | |
[textField becomeFirstResponder]; | |
self.backgroundColor = [UIColor whiteColor]; | |
} | |
return self; | |
} | |
- (void)setSelected:(BOOL)selected animated:(BOOL)animated | |
{ | |
[super setSelected:selected animated:animated]; | |
} | |
- (void)dealloc{ | |
[textField release]; | |
[super dealloc]; | |
} | |
#pragma mark - Properties | |
- (void)setName:(NSString *)aName{ | |
textField.placeholder = aName; | |
} | |
- (NSString*)Name{ | |
return textField.placeholder; | |
} | |
- (void)setValue:(NSMutableDictionary *)aValue{ | |
Value = aValue; | |
textField.placeholder = [Value valueForKey:@"Name"]; | |
} | |
- (NSString*)StringValue{ | |
return [textField.text copy]; | |
} | |
#pragma mark - Layouts | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
CGSize textSize = [@"TEST" sizeWithFont:textField.font]; | |
int yDiff = textSize.height < self.bounds.size.height ? (self.bounds.size.height - textSize.height) /2 : 5; | |
textField.frame = CGRectInset(self.bounds, 25, yDiff); | |
NSNumber *securedText = [self.Value objectForKey:@"SecuredText"]; | |
if ( securedText != nil) { | |
[textField setSecureTextEntry:[securedText boolValue]]; | |
} | |
} | |
- (void)setNeedsDisplay{ | |
textField.placeholder = self.Name; | |
} | |
#pragma mark - UITextViewDelegate | |
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ | |
return YES; | |
} | |
- (void)textFieldDidEndEditing:(UITextField *)aTextField{ | |
[textField setUserInteractionEnabled:NO]; | |
[self.Value setValue:aTextField.text forKey:@"Value"]; | |
} | |
- (BOOL)textFieldShouldReturn:(UITextField *)aTextField { | |
[aTextField resignFirstResponder]; | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment