This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue #1
- Loading branch information
Showing
5 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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 |
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
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 |
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
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 |
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