Created
May 4, 2011 20:19
-
-
Save jeksys/955948 to your computer and use it in GitHub Desktop.
EditableViewCell
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
// | |
// EditableViewCell.h | |
// Editable UITableViewCell with a UITextField as an edit tool | |
// Created by Eugene Yagrushkin on 11-05-04. | |
// Copyright 2011 Eugene Yagrushkin All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface EditableViewCell : UITableViewCell { | |
CGRect editRect; | |
UITextField *editField; | |
} | |
@property (nonatomic, readonly, retain) UITextField *editField; | |
- (void) SaveTitle; | |
@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
// | |
// EditableViewCell.m | |
// | |
// Created by Eugene Yagrushkin on 11-05-04. | |
// Copyright 2011 Eugene Yagrushkin All rights reserved. | |
// | |
#import "EditableViewCell.h" | |
@implementation EditableViewCell | |
@synthesize editField; | |
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { | |
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | |
if (self) { | |
// Initialization code. | |
editRect = CGRectMake(83, 12, self.contentView.bounds.size.width-83, 19); | |
editField = [[UITextField alloc] initWithFrame:editRect]; | |
editField.font = [UIFont boldSystemFontOfSize:15]; | |
editField.textAlignment = UITextAlignmentLeft; | |
editField.textColor = [UIColor blackColor]; | |
editField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; | |
[self.contentView addSubview:editField]; | |
[self.contentView bringSubviewToFront:editField]; | |
self.editField.enabled = NO; | |
self.editField.hidden = YES; | |
} | |
return self; | |
} | |
-(void)layoutSubviews | |
{ | |
[super layoutSubviews]; | |
editRect = CGRectMake(self.textLabel.frame.origin.x, self.textLabel.frame.origin.y, self.contentView.frame.size.width-self.textLabel.frame.origin.x, self.textLabel.frame.size.height); | |
editField.frame = editRect;//CGRectMake(0, 0, 200, 30); | |
} | |
- (void)willTransitionToState:(UITableViewCellStateMask)state { | |
[super willTransitionToState:state]; | |
if (state & UITableViewCellStateEditingMask) { | |
self.textLabel.hidden = YES; | |
self.editField.enabled = YES; | |
self.editField.hidden = NO; | |
self.editField.text = self.textLabel.text; | |
} | |
} | |
- (void)didTransitionToState:(UITableViewCellStateMask)state { | |
[super didTransitionToState:state]; | |
if (!(state & UITableViewCellStateEditingMask)) { | |
self.editField.enabled = NO; | |
self.editField.hidden = YES; | |
self.textLabel.hidden = NO; | |
self.textLabel.text = self.editField.text; | |
[self SaveTitle]; | |
} | |
} | |
- (void)dealloc { | |
[editField release]; | |
[super dealloc]; | |
} | |
- (void) SaveTitle | |
{ | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment