Skip to content

Commit

Permalink
* Fix a crash in text field table cells
Browse files Browse the repository at this point in the history
* Add beginsWithString method to complement endsWithString
  • Loading branch information
joehewitt committed May 1, 2009
1 parent 710ecef commit 9c083f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/NSStringAdditions.m
Expand Up @@ -15,7 +15,25 @@ - (BOOL)isWhitespace {
return YES;
}

- (BOOL)beginsWithString:(NSString*)substring {
if (self.length < substring.length) {
return NO;
} else {
NSRange searchRange = NSMakeRange(0, substring.length);
NSRange range = [self rangeOfString:substring options:0 range:searchRange];
return range.location == searchRange.location;
}
}

- (BOOL)endsWithString:(NSString*)substring {
if (self.length < substring.length) {
return NO;
} else {
NSRange searchRange = NSMakeRange(self.length - substring.length, substring.length);
NSRange range = [self rangeOfString:substring options:0 range:searchRange];
return range.location == searchRange.location;
}

NSRange range = [self rangeOfString:substring];
return range.location == self.length - substring.length;
}
Expand Down
4 changes: 1 addition & 3 deletions src/TTTableField.m
Expand Up @@ -260,7 +260,7 @@ - (void)dealloc {

@implementation TTTextFieldTableField

@synthesize delegate = _delegate, text = _text, title = _title, placeholder = _placeholder,
@synthesize delegate = _delegate, title = _title, placeholder = _placeholder,
returnKeyType = _returnKeyType, keyboardType = _keyboardType,
autocorrectionType = _autocorrectionType, autocapitalizationType = _autocapitalizationType,
clearButtonMode = _clearButtonMode, secureTextEntry = _secureTextEntry;
Expand All @@ -269,7 +269,6 @@ - (id)init {
if (self = [super init]) {
_delegate = nil;
_title = nil;
_text = nil;
_placeholder = nil;
_returnKeyType = UIReturnKeyDefault;
_keyboardType = UIKeyboardTypeDefault;
Expand Down Expand Up @@ -297,7 +296,6 @@ - (id)initWithTitle:(NSString*)title text:(NSString*)text {

- (void)dealloc {
[_title release];
[_text release];
[_placeholder release];
[super dealloc];
}
Expand Down
1 change: 1 addition & 0 deletions src/Three20/NSStringAdditions.h
Expand Up @@ -5,6 +5,7 @@

- (BOOL)isWhitespace;

- (BOOL)beginsWithString:(NSString*)substring;
- (BOOL)endsWithString:(NSString*)substring;

- (NSDictionary*)queryDictionaryUsingEncoding: (NSStringEncoding)encoding;
Expand Down

0 comments on commit 9c083f7

Please sign in to comment.