Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Cell that represents editable value
Browse files Browse the repository at this point in the history
Fixes issue #1
  • Loading branch information
rbsgn committed Jul 25, 2010
1 parent c1e8af4 commit b4da1a2
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Classes/YXEditableCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// YXEditableCell.h
// YXModelTableViews
//
// Created by Roman Busyghin on 7/23/10.
// Copyright 2010 Яндекс. All rights reserved.
//

#import "YXAbstractCell.h"


@interface YXEditableCell : YXAbstractCell {
@private
NSString * placeholder_;
id target_;
SEL action_;
}

+ (id)cellWithReuseIdentifier:(NSString *)reuseIdentifier target:(id)target
action:(SEL)action
placeholder:(NSString *)placeholder;

@property (nonatomic, copy, readonly) NSString * placeholder;
@property (nonatomic, assign, readonly) id target;
@property (nonatomic, assign, readonly) SEL action;

@end
70 changes: 70 additions & 0 deletions Classes/YXEditableCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// YXEditableCell.m
// YXModelTableViews
//
// Created by Roman Busyghin on 7/23/10.
// Copyright 2010 Яндекс. All rights reserved.
//

#import "YXEditableCell.h"
#import "YXEditableViewCell.h"


@interface YXEditableCell ()

@property (nonatomic, copy, readwrite) NSString * placeholder;
@property (nonatomic, assign, readwrite) id target;
@property (nonatomic, assign, readwrite) SEL action;

@end



@implementation YXEditableCell

- (void)dealloc {
[placeholder_ release];

[super dealloc];
}

+ (id)cellWithReuseIdentifier:(NSString*)reuseIdentifier target:(id)target
action:(SEL)action placeholder:(NSString *)placeholder
{
YXEditableCell * cell = [[YXEditableCell alloc] initWithReuseIdentifier:reuseIdentifier];

cell.target = target;
cell.action = action;
cell.placeholder = placeholder;

return [cell autorelease];
}

- (UITableViewCell *)tableViewCellWithReusableCell:(UITableViewCell *)reusableCell {
YXEditableViewCell * cell = nil;

if (reusableCell == nil) {
cell = [[[YXEditableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:self.reuseIdentifier] autorelease];
}
else {
cell = (YXEditableViewCell *)reusableCell;
}


cell.placeholder = self.placeholder;
cell.target = self;
cell.action = @selector(textDidChange:);

return cell;
}

- (void)textDidChange:(UITextField *)textField {
[self.target performSelector:self.action withObject:self withObject:textField];
}

@synthesize placeholder = placeholder_;
@synthesize target = target_;
@synthesize action = action_;

@end
25 changes: 25 additions & 0 deletions Classes/YXEditableViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// YXEditableViewCell.h
// YXModelTableViews
//
// Created by Roman Busyghin on 7/23/10.
// Copyright 2010 Яндекс. All rights reserved.
//

#import <UIKit/UIKit.h>

// Doesn't implement valueSuffixLabel_

@interface YXEditableViewCell : UITableViewCell <UITextFieldDelegate> {
@private
UITextField * textField_;
UILabel * valueSuffixLabel_;
id target_;
SEL action_;
}

@property (nonatomic, assign) id target;
@property (nonatomic, assign) SEL action;
@property (nonatomic, retain) NSString * placeholder;

@end
67 changes: 67 additions & 0 deletions Classes/YXEditableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// YXEditableViewCell.m
// YXModelTableViews
//
// Created by Roman Busyghin on 7/23/10.
// Copyright 2010 Яндекс. All rights reserved.
//

#import "YXEditableViewCell.h"

@interface YXEditableViewCell ()

@property (nonatomic, retain) UITextField * textField;

@end

@implementation YXEditableViewCell

static const CGFloat kTextFieldMargin = 10.0f;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
textField_ = [[UITextField alloc] initWithFrame:CGRectZero];
textField_.delegate = self;
textField_.font = [UIFont systemFontOfSize:17.0f];
textField_.textColor = [UIColor blackColor];
textField_.textAlignment = UITextAlignmentLeft;
textField_.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:textField_];
}
return self;
}

- (void)layoutSubviews {
[super layoutSubviews];

CGRect textFieldFrame = CGRectInset(self.contentView.bounds, kTextFieldMargin, 0.0f);
self.textField.frame = textFieldFrame;
}

- (void)setPlaceholder:(NSString *)newPlaceholder {
self.textField.placeholder = newPlaceholder;
}

- (NSString *)placeholder {
return self.textField.placeholder;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
[self.target performSelector:self.action withObject:textField];
}

@synthesize textField = textField_;
@synthesize target = target_;
@synthesize action = action_;


- (void)dealloc {
[textField_ release];

[super dealloc];
}


@end
12 changes: 12 additions & 0 deletions YXModelTableViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
5CC8289111999EA600EE72E3 /* YXModelTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5CC8289011999EA600EE72E3 /* YXModelTableViewController.m */; };
C9B1596C11FC7419007FAE69 /* YXCheckmarkCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9B1596B11FC7419007FAE69 /* YXCheckmarkCell.m */; };
C9B1597D11FC7905007FAE69 /* YXCheckmarkCellGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = C9B1597C11FC7905007FAE69 /* YXCheckmarkCellGroup.m */; };
C9BB459011FCD06C0081D3C2 /* YXEditableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9BB458D11FCD06C0081D3C2 /* YXEditableCell.m */; };
C9BB459111FCD06C0081D3C2 /* YXEditableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9BB458F11FCD06C0081D3C2 /* YXEditableViewCell.m */; };
C9BC424F11F589F100F1AEA8 /* YXSegmentedControlCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9BC424E11F589F100F1AEA8 /* YXSegmentedControlCell.m */; };
C9BC425611F58C7900F1AEA8 /* YXSegmentedControlViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9BC425511F58C7900F1AEA8 /* YXSegmentedControlViewCell.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -61,6 +63,10 @@
C9B1596B11FC7419007FAE69 /* YXCheckmarkCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YXCheckmarkCell.m; sourceTree = "<group>"; };
C9B1597B11FC7905007FAE69 /* YXCheckmarkCellGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YXCheckmarkCellGroup.h; sourceTree = "<group>"; };
C9B1597C11FC7905007FAE69 /* YXCheckmarkCellGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YXCheckmarkCellGroup.m; sourceTree = "<group>"; };
C9BB458C11FCD0610081D3C2 /* YXEditableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YXEditableCell.h; sourceTree = "<group>"; };
C9BB458D11FCD06C0081D3C2 /* YXEditableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YXEditableCell.m; sourceTree = "<group>"; };
C9BB458E11FCD06C0081D3C2 /* YXEditableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YXEditableViewCell.h; sourceTree = "<group>"; };
C9BB458F11FCD06C0081D3C2 /* YXEditableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YXEditableViewCell.m; sourceTree = "<group>"; };
C9BC424D11F589F100F1AEA8 /* YXSegmentedControlCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YXSegmentedControlCell.h; sourceTree = "<group>"; };
C9BC424E11F589F100F1AEA8 /* YXSegmentedControlCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YXSegmentedControlCell.m; sourceTree = "<group>"; };
C9BC425411F58C7900F1AEA8 /* YXSegmentedControlViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YXSegmentedControlViewCell.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -170,6 +176,10 @@
C9B1596B11FC7419007FAE69 /* YXCheckmarkCell.m */,
C9B1597B11FC7905007FAE69 /* YXCheckmarkCellGroup.h */,
C9B1597C11FC7905007FAE69 /* YXCheckmarkCellGroup.m */,
C9BB458C11FCD0610081D3C2 /* YXEditableCell.h */,
C9BB458D11FCD06C0081D3C2 /* YXEditableCell.m */,
C9BB458E11FCD06C0081D3C2 /* YXEditableViewCell.h */,
C9BB458F11FCD06C0081D3C2 /* YXEditableViewCell.m */,
);
name = "Model Table View";
sourceTree = "<group>";
Expand Down Expand Up @@ -242,6 +252,8 @@
C9BC425611F58C7900F1AEA8 /* YXSegmentedControlViewCell.m in Sources */,
C9B1596C11FC7419007FAE69 /* YXCheckmarkCell.m in Sources */,
C9B1597D11FC7905007FAE69 /* YXCheckmarkCellGroup.m in Sources */,
C9BB459011FCD06C0081D3C2 /* YXEditableCell.m in Sources */,
C9BB459111FCD06C0081D3C2 /* YXEditableViewCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit b4da1a2

Please sign in to comment.