Today's Menu  Portugal
journal and plan nutrition
Y3RecipeCheckViewController.m
Go to the documentation of this file.
1 //
2 // Y3RecipeCheckViewController.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 4/14/16.
6 // Copyright © 2016 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
11 #import "Z5DataController.h"
12 
13 @interface Y3RecipeCheckViewController ()
14 
15 @property (strong, nonatomic) MenuItem *focusMenuItem;
16 @end
17 
18 @implementation Y3RecipeCheckViewController
19 
20 UITextView *recipeViewTextView;
22 
23 - (id) initWithMenuItem:(MenuItem *)menuItem
24 {
25  self = [super init];
26  self.focusMenuItem = menuItem;
27  return self;
28 }
29 
30 - (void)viewDidLoad {
31  [super viewDidLoad];
32  // Do any additional setup after loading the view.
33  CGRect totalFrame = self.view.frame;
34  [self.view setBackgroundColor:[UIColor greenColor]];
35 
36  CGRect recipeViewFrame = CGRectMake(totalFrame.size.width*0.05,
37  totalFrame.origin.y+totalFrame.size.height*0.180,
38  totalFrame.size.width*0.9,
39  220.0);
40  recipeViewTextView = [[UITextView alloc] initWithFrame:recipeViewFrame];
41  [recipeViewTextView setBackgroundColor:[UIColor whiteColor]];
42  [self.view addSubview:recipeViewTextView];
43 
44  CGRect usdaDataViewFrame = CGRectMake(totalFrame.size.width*0.05,
45  totalFrame.origin.y+totalFrame.size.height*0.180 + 240,
46  totalFrame.size.width*0.9,
47  220.0);
48  usdaDataViewTextView = [[UITextView alloc] initWithFrame:usdaDataViewFrame];
49  [usdaDataViewTextView setBackgroundColor:[UIColor yellowColor]];
50  [self.view addSubview:usdaDataViewTextView];
51 
52  UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Entry" style:UIBarButtonItemStylePlain target:self action:@selector(fireParameterEntry)];
53  self.navigationItem.rightBarButtonItem = anotherButton;
54 }
55 
56 - (void)viewWillAppear:(BOOL)animated
57 {
58  [recipeViewTextView setText:[self.focusMenuItem recipe]];
59  [usdaDataViewTextView setText:[self.focusMenuItem usdaNumbers]];
60 }
61 
62 - (void)viewWillDisappear:(BOOL)animated
63 {
64  [super viewWillDisappear:animated];
65 
66  // NSString *newStr = [m5mo bodytext];
67  // NSData* data = [newStr dataUsingEncoding:NSUTF8StringEncoding];
68  //
69  [[[Z5DataController sharedInstance] localDataController] saveContext];
70  NSLog(@"RecipeCheckController.viewWillDisappear: usdaNumbers: %@", [self.focusMenuItem usdaNumbers]);
71 
72  NSError *error;
73  NSData *data = [[self.focusMenuItem usdaNumbers] dataUsingEncoding:NSUTF8StringEncoding];
74  if (data) {
75  NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data
76  options:kNilOptions
77  error:&error];
78  if (error) {
79  NSLog(@"RecipeCheckController.viewWillDisappear: error: %@", error);
80  } else {
81  NSLog(@"RecipeCheckController.viewWillDisappear: jsonResponse: %@", jsonResponse);
82  }
83  }
84 }
85 
87 {
88  if (nil != self.focusMenuItem) {
89  self.focusMenuItem.recipe = recipeViewTextView.text;
90  self.focusMenuItem.usdaNumbers = usdaDataViewTextView.text;
91 
92  NSLog(@"CollectionView.fireParameterEntry: focusMenuItem: %@", self.focusMenuItem);
93 
94  Y4UsdaParamEntryViewController *parameterView =
95  [[Y4UsdaParamEntryViewController alloc] initWithMenuItem:[self focusMenuItem]];
96  [self.navigationController pushViewController:parameterView animated:YES];
97  } else {
98  NSLog(@"CollectionView.fireParameterEntry: nil focusMenuItem");
99  }
100 }
101 
103  [super didReceiveMemoryWarning];
104  // Dispose of any resources that can be recreated.
105 }
106 
107 
108 @end
MenuItem * menuItem
instancetype sharedInstance()
UITextView * usdaDataViewTextView
Singleton interface to both core and remote data sources.
UITextView * recipeViewTextView