Today's Menu  Portugal
journal and plan nutrition
V7UsdaFoodsTableView.m
Go to the documentation of this file.
1 //
2 // V7UsdaFoodsTableView.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 6/21/18.
6 // Copyright © 2018 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
10 #import "Z5DataController.h"
11 
12 @implementation V7UsdaFoodsTableView
13 {
14  id<V7UsdaFoodsTableDelegate> dataDelegate;
15 }
16 - (id) initWithFrame:(CGRect)frame
17  andHeader:(UIView *)headerView
18  inContainer:(id<V7UsdaFoodsTableDelegate>) container
19 {
20  NSLog(@"Z7UsdaFoodsTableView.init");
21 
22  self = [super initWithFrame:frame];
23  [self setTableHeaderView:headerView];
24  [self setBackgroundColor:[[Z5DataController sharedInstance] wheatColor]];
25  self.dataSource = self;
26 
27  dataDelegate = container;
28 
29 // mDateFormatter = [[NSDateFormatter alloc] init];
30 // [mDateFormatter setTimeStyle:NSDateFormatterNoStyle];
31 // [mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
32 
33  return self;
34 }
35 
36 
37 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
38 {
39  NSArray<NSDictionary *> *foodEntries = [dataDelegate retrieveFoodEntries];
40  NSInteger nMesgs = [foodEntries count];
41  return nMesgs;
42 }
43 
44 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
45 {
46  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"todays-menu"];
47  NSLog(@"V7UsdaFoodsTableView.cellForRow: cell: %@", cell);
48  if (cell == nil) {
49  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"todays-menu"];
50 
51  cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
52 
53  CGRect contentRect = [cell.contentView frame];
54  CGRect fetchPublishButton1Frame = CGRectMake(contentRect.size.width - 86.0f, 5.0, 34.0f, contentRect.size.height - 10);
55  UIButton *pushMe = [[UIButton alloc] initWithFrame:fetchPublishButton1Frame];
56  [pushMe setTitle:@"GO" forState:UIControlStateApplication];
57 
58  [cell.contentView addSubview:pushMe];
59  }
60 
61  NSArray<NSDictionary *> *foodEntries = [dataDelegate retrieveFoodEntries];
62  NSInteger nMesgs = [foodEntries count];
63 
64  if (nMesgs > [indexPath row]) {
65  NSDictionary *foodForCell = [foodEntries objectAtIndex:[indexPath row]];
66  NSString *caption = [foodForCell objectForKey:@"name"];
67  [Z5DataController labelizeCell:cell withText:caption inColor:[UIColor lightGrayColor] andDetail:@"more"];
68  }
69 
70  return cell;
71 
72 }
73 
75 {
76  NSArray<NSDictionary *> *foodEntries = [dataDelegate retrieveFoodEntries];
77  NSInteger nFoods = [foodEntries count];
78 
79  float ret = [super getViewHeightReqmt] + nFoods * 42.0;
80  NSLog(@"V7UsdaFoodsTableView.getViewHeightReqmt: ret: %3.2f", ret);
81  return ret;
82 }
83 
84 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
85  // int row = (int)[indexPath row];
86 
87  /*
88  Z5EmailDataController *eMailCntrlr = [[[Z5DataController sharedInstance] remoteDataController] emailDataController];
89 
90  _focusEmailMsg = [[dataDelegate retrieveEmailMessages] objectAtIndex:[indexPath row]];
91  NSLog(@"V7UsdaFoodsTableView.tableView:didSelectRowAtIndexPath: focusEmail: bodytext: %@ date: %@ name: %@ randomkey: %@ remoteUniqueId: %@ uid: %@", [_focusEmailMsg bodytext], [_focusEmailMsg date], [_focusEmailMsg name], [_focusEmailMsg randomkey], [_focusEmailMsg remoteUniqueIID], [_focusEmailMsg uid]);
92 
93  NSString *caption = [_focusEmailMsg name];
94 
95  NSLog(@"V7UsdaFoodsTableView.tableView:didSelectRowAtIndexPath: row: %d caption: %@", row, caption);
96 
97  NSInteger focusEmailMsgUid = [_focusEmailMsg.uid integerValue];
98 
99  if ([_focusEmailMsg randomkey]) {
100  NSData *mphoto = [_focusEmailMsg photo];
101  UIImage *mPhotoImage = [UIImage imageWithData:_focusEmailMsg.photo];
102  [dataDelegate updateHTML:[_focusEmailMsg bodytext]];
103  } else {
104  [eMailCntrlr retrieveMessageStructure:focusEmailMsgUid fromFolder:@"INBOX"];
105  [eMailCntrlr retrieveTotalMessageHTML:focusEmailMsgUid fromFolder:@"INBOX" toDelegate:dataDelegate];
106  }
107 
108  [self showFoot:YES];
109  [self reloadData];
110  [self setNeedsDisplay];
111  [self scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
112  */
113 }
114 
115 /*
116 // Only override drawRect: if you perform custom drawing.
117 // An empty implementation adversely affects performance during animation.
118 - (void)drawRect:(CGRect)rect {
119  // Drawing code
120 }
121 */
122 
123 @end
id initWithFrame:(CGRect frame)
instancetype sharedInstance()
Singleton interface to both core and remote data sources.
void labelizeCell:withText:inColor:andDetail:(UITableViewCell *targCell, [withText] NSString *txt, [inColor] UIColor *color, [andDetail] NSString *detailTxt)