rt300@11
|
1 //
|
rt300@11
|
2 // iViewController.m
|
rt300@11
|
3 // oscSenderExample
|
rt300@11
|
4 //
|
rt300@11
|
5 // Created by Robert Tubb on 07/01/2013.
|
rt300@11
|
6 //
|
rt300@11
|
7 //
|
rt300@11
|
8 #include "testApp.h"
|
rt300@11
|
9 #import "PresetAlertViewController.h"
|
rt300@11
|
10
|
rt300@11
|
11
|
rt300@11
|
12 @implementation PresetAlertViewController
|
rt300@11
|
13 - (PresetAlertViewController *) init{
|
rt300@11
|
14 [super init];
|
rt300@11
|
15 self = [super init];
|
rt300@11
|
16 if (self) {
|
rt300@11
|
17 // Custom initialization
|
rt300@11
|
18
|
rt300@11
|
19 self.alertShowing = NO;
|
rt300@11
|
20
|
rt300@11
|
21 }
|
rt300@11
|
22 return self;
|
rt300@11
|
23
|
rt300@11
|
24 }
|
rt300@11
|
25 - (void)showPresetNamePrompt{
|
rt300@11
|
26 self.alert = [[UIAlertView alloc] initWithTitle:@"Save"
|
rt300@11
|
27 message:@"Enter preset name:"
|
rt300@11
|
28 delegate:self
|
rt300@11
|
29 cancelButtonTitle:@"Cancel"
|
rt300@11
|
30 otherButtonTitles:@"Enter",nil];
|
rt300@11
|
31 self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
|
rt300@11
|
32 UITextField * alertTextField = [self.alert textFieldAtIndex:0];
|
rt300@11
|
33 [alertTextField setDelegate:self];
|
rt300@11
|
34 alertTextField.keyboardType = UIKeyboardTypeDefault;
|
rt300@11
|
35 alertTextField.placeholder = @"Preset Name";
|
rt300@11
|
36 [self.alert show];
|
rt300@11
|
37 self.alertShowing = YES;
|
rt300@11
|
38 // [self.alert release];
|
rt300@11
|
39 }
|
rt300@11
|
40
|
rt300@11
|
41 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
rt300@11
|
42
|
rt300@11
|
43 NSLog(@"Preset save %@", [[alertView textFieldAtIndex:0] text]);
|
rt300@11
|
44 if(buttonIndex == 0){
|
rt300@11
|
45 // cancel
|
rt300@11
|
46 NSLog(@"preset save was cancelled");
|
rt300@11
|
47 self.alertShowing = NO;
|
rt300@11
|
48 }else{
|
rt300@11
|
49 // save it
|
rt300@11
|
50 self.alertShowing = NO;
|
rt300@12
|
51
|
rt300@12
|
52 ((testApp *)ofGetAppPtr())->savePreset([[[self.alert textFieldAtIndex:0] text] cStringUsingEncoding:NSASCIIStringEncoding]);
|
rt300@12
|
53
|
rt300@11
|
54 }
|
rt300@11
|
55 }
|
rt300@11
|
56
|
rt300@11
|
57 -(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
rt300@11
|
58 // save it
|
rt300@11
|
59 self.alertShowing = NO;
|
rt300@12
|
60
|
rt300@12
|
61 ((testApp *)ofGetAppPtr())->savePreset([[[self.alert textFieldAtIndex:0] text] cStringUsingEncoding:NSASCIIStringEncoding]);
|
rt300@12
|
62
|
rt300@11
|
63 [self.alert dismissWithClickedButtonIndex:self.alert.firstOtherButtonIndex animated:YES];
|
rt300@11
|
64 return YES;
|
rt300@11
|
65 }
|
rt300@11
|
66
|
rt300@11
|
67 - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
|
rt300@11
|
68 {
|
rt300@11
|
69 UITextField *textField = [alertView textFieldAtIndex:0];
|
rt300@11
|
70 if ([textField.text length] == 0)
|
rt300@11
|
71 {
|
rt300@11
|
72 return NO;
|
rt300@11
|
73 }
|
rt300@11
|
74 return YES;
|
rt300@11
|
75 }
|
rt300@11
|
76
|
rt300@11
|
77
|
rt300@11
|
78
|
rt300@11
|
79 @end
|
rt300@11
|
80
|
rt300@11
|
81
|
rt300@11
|
82 // global? again.
|
rt300@11
|
83 PresetAlertViewController *presetAlertViewController = [[PresetAlertViewController alloc] init];
|