-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrencyEditor.m
93 lines (79 loc) · 3.12 KB
/
CurrencyEditor.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// CurrencyEditor.m
// Allowance
//
// Created by Pablo Collins on 8/15/10.
//
#import "CurrencyEditor.h"
@implementation CurrencyEditor
@synthesize reloadableParent;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Format";
delims = [NSArray arrayWithObjects:@".",@",",@"",nil];
symbols = [NSArray arrayWithObjects:@"$",@"£",@"€",@"¥",@"₩",@"₪",@"₨",@"¤",@"♥",nil];
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *whiteImage = [UIImage imageNamed:@"whiteButton.png"];
CGRect f1 = CGRectMake(10, 260, 300, 40);
UIButton *btn = [AllowanceAppDelegate newButtonWithTitle:@"OK"
target:self
selector:@selector(save:)
frame:f1
image:whiteImage
imagePressed:blueImage
darkTextColor:YES];
NSString *delim = [AllowanceAppDelegate delimiter];
NSString *currency = [AllowanceAppDelegate currency];
[picker selectRow:[symbols indexOfObject:currency] inComponent:0 animated:NO];
[picker selectRow:[delims indexOfObject:delim] inComponent:1 animated:NO];
[self print];
[self.view addSubview:btn];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 60;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0) {
return [symbols count];
} else {
return [delims count];
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0) {
return [symbols objectAtIndex:row];
} else {
return [NSString stringWithFormat:@"'%@'",[delims objectAtIndex:row]];
}
}
- (void)print {
NSInteger currencyRow = [picker selectedRowInComponent:0];
NSInteger delimRow = [picker selectedRowInComponent:1];
NSString *symbol = [symbols objectAtIndex:currencyRow];
NSString *delim = [delims objectAtIndex:delimRow];
label.text = [NSString stringWithFormat:@"%@12%@34",symbol,delim];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
[self print];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)save:(id)sender {
int c0 = [picker selectedRowInComponent:0];
int c1 = [picker selectedRowInComponent:1];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *symbol = [symbols objectAtIndex:c0];
NSString *delim = [delims objectAtIndex:c1];
[defaults setObject:symbol forKey:@"currency"];
[defaults setObject:delim forKey:@"delimeter"];
[reloadableParent readAndReload];
[self.navigationController popViewControllerAnimated:YES];
}
@end