Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates for making it work better

  • Loading branch information...
commit e1a5e4fbac34dc0ec2246e4a779f5cade506063d 1 parent 270ac5f
@jivadevoe jivadevoe authored
Showing with 32 additions and 22 deletions.
  1. +9 −14 Classes/ELCTextfieldCell.h
  2. +23 −8 Classes/ELCTextfieldCell.m
View
23 Classes/ELCTextfieldCell.h
@@ -8,25 +8,20 @@
#import <UIKit/UIKit.h>
+@class ELCTextfieldCell;
-@interface ELCTextfieldCell : UITableViewCell <UITextFieldDelegate> {
-
- id delegate;
- UILabel *leftLabel;
- UITextField *rightTextField;
- NSIndexPath *indexPath;
-}
+@protocol ELCTextFieldDelegate <NSObject>
+@optional
+-(BOOL)textField:(ELCTextfieldCell *)inCell shouldReturnForIndexPath:(NSIndexPath*)inIndexPath withValue:(NSString *)inValue;
+-(void)textField:(ELCTextfieldCell *)inCell didReturnWithIndexPath:(NSIndexPath*)inIndexPath withValue:(NSString *)inValue;
+-(void)textField:(ELCTextfieldCell *)inCell updateTextLabelAtIndexPath:(NSIndexPath *)inIndexPath string:(NSString *)inValue;
+@end
-@property (nonatomic, assign) id delegate;
+@interface ELCTextfieldCell : UITableViewCell <UITextFieldDelegate>
+@property (nonatomic, assign) id<ELCTextFieldDelegate> delegate;
@property (nonatomic, retain) UILabel *leftLabel;
@property (nonatomic, retain) UITextField *rightTextField;
@property (nonatomic, retain) NSIndexPath *indexPath;
@end
-@protocol ELCTextFieldDelegate
-
--(void)textFieldDidReturnWithIndexPath:(NSIndexPath*)_indexPath;
--(void)updateTextLabelAtIndexPath:(NSIndexPath*)_indexPath string:(NSString*)_string;
-
-@end
View
31 Classes/ELCTextfieldCell.m
@@ -65,16 +65,30 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
+- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
+{
+ return YES;
+}
+
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
- if([delegate respondsToSelector:@selector(textFieldDidReturnWithIndexPath:)]) {
-
- [delegate performSelector:@selector(textFieldDidReturnWithIndexPath:) withObject:indexPath];
+ BOOL ret = YES;
+ if([delegate respondsToSelector:@selector(textField:shouldReturnForIndexPath:withValue:)])
+ {
+ ret = [delegate textField:self shouldReturnForIndexPath:indexPath withValue:self.rightTextField.text];
}
-
- return YES;
+ if(ret)
+ [textField resignFirstResponder];
+ return ret;
+}
+
+- (void)textFieldDidEndEditing:(UITextField *)textField
+{
+ if([delegate respondsToSelector:@selector(textField:didReturnWithIndexPath:withValue:)])
+ [delegate textField:self didReturnWithIndexPath:indexPath withValue:self.rightTextField.text];
}
+
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *textString = self.rightTextField.text;
@@ -97,15 +111,16 @@ - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRan
}
}
- if([delegate respondsToSelector:@selector(updateTextLabelAtIndexPath:string:)]) {
- [delegate performSelector:@selector(updateTextLabelAtIndexPath:string:) withObject:indexPath withObject:textString];
+ if([delegate respondsToSelector:@selector(textField:updateTextLabelAtIndexPath:string:)])
+ {
+ [delegate textField:self updateTextLabelAtIndexPath:indexPath string:textString];
}
return YES;
}
- (void)dealloc {
- [rightTextField resignFirstResponder];
+ [rightTextField resignFirstResponder];
[leftLabel release];
[rightTextField release];
[indexPath release];
Please sign in to comment.
Something went wrong with that request. Please try again.