-
Notifications
You must be signed in to change notification settings - Fork 0
/
MilesDelegate.m
46 lines (36 loc) · 1.18 KB
/
MilesDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// MilesDelegate.m
// Tabbed Conversion
//
// Created by Scott Ashmore on 12-01-19.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "MilesDelegate.h"
@implementation MilesDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.length >0 && [string length] ==0) {
return YES;
}
NSCharacterSet *characterSet;
NSString *numberSet=@"0123456789";
NSString *numberPeriodSet=@"0123456789.";
NSRange seperatorRange=[textField.text rangeOfString:@"."];
if (seperatorRange.location == NSNotFound) {
characterSet=[[NSCharacterSet characterSetWithCharactersInString:numberPeriodSet]invertedSet];
}
else {
characterSet=[[NSCharacterSet characterSetWithCharactersInString:numberSet]invertedSet];
}
return ([[string stringByTrimmingCharactersInSet:characterSet] length] > 0);
}
-(void) textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"text field ended editing");
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
@end