linphone-ios/Classes/LinphoneUI/UIEditableTableViewCell.m
2012-07-10 15:57:55 +02:00

100 lines
3.1 KiB
Objective-C

/* UIEditableTableViewCell.m
*
* Copyright (C) 2012 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "UIEditableTableViewCell.h"
@implementation UIEditableTableViewCell
@synthesize detailTextField;
#pragma mark - Lifecycle Functions
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIView *parent = [self.detailTextLabel superview];
self.detailTextField = [[UITextField alloc] init];
[self.detailTextField setHidden:TRUE];
[self.detailTextField setDelegate:self];
[self.detailTextField setClearButtonMode: UITextFieldViewModeWhileEditing];
[self.detailTextField setContentVerticalAlignment: UIControlContentVerticalAlignmentCenter];
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:[UIFont systemFontSize]];
[self.detailTextLabel setFont:font];
[self.detailTextField setFont:font];
[parent addSubview:detailTextField];
}
return self;
}
- (void)dealloc {
[self.detailTextField release];
[super dealloc];
}
#pragma mark - View Functions
- (void)layoutSubviews {
[super layoutSubviews];
CGRect frame;
frame.origin.x = 83;
frame.origin.y = 0;
frame.size.height = 44;
CGRect superframe = [self frame];
frame.size.width = superframe.size.width - frame.origin.x - 10;
[self.detailTextField setFrame:frame];
}
#pragma mark - UITableViewCell Functions
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if(editing) {
[self.detailTextField setHidden:FALSE];
[self.detailTextLabel setHidden:TRUE];
} else {
[self.detailTextField setHidden:TRUE];
[self.detailTextLabel setHidden:FALSE];
}
}
- (void)setEditing:(BOOL)editing {
[self setEditing:editing animated:FALSE];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
#pragma mark - UITextFieldDelegate Functions
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
@end