Permalink
Browse files

Merge pull request #2 from jivadevoe/master

Fixing a bug related to cell deallocation
  • Loading branch information...
2 parents 5c043ea + e1a5e4f commit 5e0c9c3442806d1264f7804e761afcef95f94e43 jvanmetre committed Dec 7, 2012
Showing with 32 additions and 22 deletions.
  1. +9 −14 Classes/ELCTextfieldCell.h
  2. +23 −8 Classes/ELCTextfieldCell.m
View
@@ -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
@@ -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];
[leftLabel release];
[rightTextField release];
[indexPath release];

0 comments on commit 5e0c9c3

Please sign in to comment.