Today's Menu  Portugal
journal and plan nutrition
Instance Methods | Properties | List of all members
U3ParameterTableView Class Reference

#import <U3ParameterTableView.h>

Inheritance diagram for U3ParameterTableView:
Inheritance graph
[legend]
Collaboration diagram for U3ParameterTableView:
Collaboration graph
[legend]

Instance Methods

(id) - initWithFrame:andComponents:inContainer:
 
(void) - addParameter:
 
(void) - updateParameter:
 
(NSInteger) - isListedAlready:
 
(void) - update:
 
(float) - getViewHeightReqmt
 
(void) - scrollInitially
 
(void) - scrollForControlPanel
 
(void) - scrollForInstructionPanel
 
(NSUInteger) - parameterCount
 
(void) - setViewForHead:
 
(void) - setViewForTail:
 
(id) - initWithFrame:andComponents:inContainer: [implementation]
 
(void) - setViewForHead: [implementation]
 
(void) - tableView:didSelectRowAtIndexPath: [implementation]
 
(NSInteger) - numberOfSectionsInTableView: [implementation]
 
(NSInteger) - tableView:numberOfRowsInSection: [implementation]
 
(UITableViewCell *) - tableView:cellForRowAtIndexPath: [implementation]
 
(CGFloat) - tableView:heightForHeaderInSection: [implementation]
 
(UIView *) - tableView:viewForHeaderInSection: [implementation]
 
(CGFloat) - tableView:heightForFooterInSection: [implementation]
 
(UIView *) - tableView:viewForFooterInSection: [implementation]
 

Properties

NSMutableArray< NSDictionary * > * givenParameters
 
id< U3ParameterTableDelegate > givenContainer
 

Detailed Description

TODO: Wrap the 'cell' in a class.

The key thing is that UIScrollView (from which UITableView inherits) messes around with the responder chain so as to always return itself in the UIView method HitTest: WithEvent: It is this method that proved to be the key to getting the scroll view to play ball. (Note: it is important NOT to implement the touchesBegan, etc methods in this subclass or else you will override the default scrolling behaviour.)

Therefore, it is vital to subclass the UITableView and override the HitTest: WithEvent method so that it returns the current UITableViewCell (which can be obtained by locating the cellAtPoint: UITableView method) unless you determine that there is some vertical finger movement or it is scrolling (i.e. where tableView.decelerating == NO), in which case return self.

The table cell itself also needs to be subclassed and all the UIResponder methods touchesBegan: , touchesMoved and touchesEnded methods must be implemented. There you can pass a method to determine whether there is any vertical movement and, if so, set the next responder to be the table view. It is also here where you implement the code to work the swiping action (Apple's example code in the Events handling guide works well here).

Then, it's just a case of cleaning up a little by resetting the various parameters in the touchesEnded method. I have a tick button on the left of my cell, so I made sure that the hitTest method in UITableView subclass always returned self if the touch.x position was < 50, but you get the gist.

It is important to make sure that the delaysContentTouches property of the UITableView is set to YES or else you won't get any scrolling. It is also a good idea to turn off the swipe editing gesture because it will interfere with the custom swiping action.

Attribution: https://forums.macrumors.com/threads/problems-accessing-touch-events-in-a-uitableview-uiscrollview.640508/

Definition at line 15 of file U3ParameterTableView.h.

Method Documentation

◆ addParameter:()

- (void) addParameter: (NSDictionary *)  newComponentSpecDict

Definition at line 127 of file U3ParameterTableView.m.

127  : (NSDictionary *)newComponentSpecDict
128 {
129  [[self givenParameters] addObject:newComponentSpecDict];
130 
131  [[self givenContainer] resizeParameterFrame];
132  [[self givenContainer] updatedParameterArray:[self givenParameters]];
133 }
NSMutableDictionary * newComponentSpecDict

◆ getViewHeightReqmt()

- (float) getViewHeightReqmt

Reimplemented in U3MenuChoicesTableView.

Definition at line 151 of file U3ParameterTableView.m.

152 {
153  paramHeaderHeight = [tableHead heightRequirement];
154 
155  float ret = paramHeaderHeight;
156  NSInteger parameterCount = [[self givenParameters] count];
157  if (0 < parameterCount){
158  ret += 2 + (parameterCount * 44);
159  }
160  NSInteger tailHeightReqmt = [tableTail heightRequirement];
161  if (0 < tailHeightReqmt) {
162  ret += 2 + [tableTail heightRequirement];
163  }
164  NSLog(@"U3ParameterTableView.getViewHeightReqmt: head: %3.2f total: %3.2f", paramHeaderHeight, ret);
165  return ret;
166 }
float paramHeaderHeight
UIView< Z6ContainedView > * tableTail

◆ initWithFrame:andComponents:inContainer:() [1/2]

- (id) initWithFrame: (CGRect)  frame
andComponents: (NSArray *)  components
inContainer: (id< U3ParameterTableDelegate >)  container 

◆ initWithFrame:andComponents:inContainer:() [2/2]

- (id) initWithFrame: (CGRect)  frame
andComponents: (NSArray<NSDictionary *>*)  components
inContainer: (id<U3ParameterTableDelegate>)  container 
implementation

Definition at line 50 of file U3ParameterTableView.m.

50  :(CGRect)frame
51  andComponents:(NSArray<NSDictionary *>*)components
52  inContainer:(id<U3ParameterTableDelegate>) container
53 {
54  NSLog(@"U3parameterTableView.init: #-components: %ld", (long)[components count]);
55 
56  self = [super initWithFrame:frame style:UITableViewStyleGrouped];
57  [self setBackgroundColor:[[Z5DataController sharedInstance] wheatColor]];
58  [self setDelegate:self];
59  self.dataSource = self;
60 
61  mDateFormatter = [[NSDateFormatter alloc] init];
62  [mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
63  [mDateFormatter setTimeStyle:NSDateFormatterShortStyle];
64 
65  [self setGivenParameters:[[NSMutableArray alloc] initWithArray:components]];
66  [self setGivenContainer:container];
67 
68  [self setScrollEnabled:YES];
69  paramHeaderHeight = 0.0f;
70  paramFooterHeight = 0.0f;
71  tableHead = nil;
72  tableTail = nil;
73 
74  return self;
75 }
float paramHeaderHeight
instancetype sharedInstance()
UIView< Z6ContainedView > * tableTail
NSDateFormatter * mDateFormatter
id< Z6ContainedView > tableHead
float paramFooterHeight
Singleton interface to both core and remote data sources.

◆ isListedAlready:()

- (NSInteger) isListedAlready: (NSString *)  checkCaption

Definition at line 111 of file U3ParameterTableView.m.

111  : (NSString *)checkCaption
112 {
113  NSInteger ret = -1;
114  int parameterIndex = 0;
115  for (NSDictionary *item in [self givenParameters]) {
116  NSString *componentType = [item objectForKey:[Z5LocalDataController componentNameKey]];
117  NSString *compoTypeClass = NSStringFromClass([componentType class]);
118  if ([componentType isEqualToString:checkCaption]) {
119  NSLog(@"Z6ParameterTableView.isListedAlready: yes, class: %@", compoTypeClass);
120  ret = parameterIndex;
121  break;
122  }
123  parameterIndex++;
124  }
125  return ret;
126 }
NSMutableArray< NSDictionary * > * givenParameters

◆ numberOfSectionsInTableView:()

- (NSInteger) numberOfSectionsInTableView: (UITableView *)  tableView
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 221 of file U3ParameterTableView.m.

221  :(UITableView *)tableView
222 {
223  NSLog(@"U3ParameterTableView.numberOfSectionsInTableView: 1");
224  // this is called at "Originate Item"?!!
225  return 1; // default is 1
226 }

◆ parameterCount()

- (NSUInteger) parameterCount

Definition at line 207 of file U3ParameterTableView.m.

208 {
209  return [[self givenParameters] count];
210 }

◆ scrollForControlPanel()

- (void) scrollForControlPanel

Definition at line 174 of file U3ParameterTableView.m.

175 {
176  NSInteger nParams = [[self givenParameters] count];
177  if ( 0 < nParams) {
178  NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:nParams-1 inSection:0];
179  [self scrollToRowAtIndexPath:lastIndex atScrollPosition:UITableViewScrollPositionBottom animated:YES];
180  }
181 }

◆ scrollForInstructionPanel()

- (void) scrollForInstructionPanel

Definition at line 182 of file U3ParameterTableView.m.

183 {
184  NSLog(@"ParameterTablView.scrollForInstructionPanel: entry");
185  NSInteger nSections = [self numberOfSections];
186  NSLog(@" .. nSections: %ld", (long)nSections);
187  for (int j=0;j<nSections;j++) {
188  NSLog(@" ... nRows, section %d: %ld", j, (long)[self numberOfRowsInSection:j]);
189  }
190  NSInteger endSection = nSections - 1;
191  NSInteger nRows = [self numberOfRowsInSection:endSection];
192 
193  if (0 < nRows) {
194  NSInteger lastRowEndSection = nRows - 1;
195  NSLog(@" .. last index: S:%ld R:%ld", (long)endSection, (long)lastRowEndSection);
196  NSAssert(!(lastRowEndSection<0), @"empty last section");
197  NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:lastRowEndSection inSection:endSection];
198  [self scrollToRowAtIndexPath:lastIndex atScrollPosition:UITableViewScrollPositionBottom animated:YES];
199  }
200  NSLog(@"ParameterTablView.scrollForInstructionPanel: exit");
201 // NSInteger nParams = [[self givenParameters] count];
202 // if ( 0 < nParams) {
203 // NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:nParams-1 inSection:0];
204 // [self scrollToRowAtIndexPath:lastIndex atScrollPosition:UITableViewScrollPositionBottom animated:YES];
205 // }
206 }

◆ scrollInitially()

- (void) scrollInitially

Definition at line 167 of file U3ParameterTableView.m.

168 {
169  if ( 0 < [[self givenParameters] count]) {
170  NSIndexPath *firstIndex = [NSIndexPath indexPathForRow:0 inSection:0];
171  [self scrollToRowAtIndexPath:firstIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];
172  }
173 }
NSMutableArray< NSDictionary * > * givenParameters

◆ setViewForHead:() [1/2]

- (void) setViewForHead: (UIView *)  headView

◆ setViewForHead:() [2/2]

- (void) setViewForHead: (id <Z6ContainedView>)  headView
implementation

Definition at line 77 of file U3ParameterTableView.m.

77  : (id <Z6ContainedView>)headView
78 {
79  tableHead = headView;
80  paramHeaderHeight = [headView heightRequirement];
81  NSLog(@"U3ParameterTableView.setViewForHead: paramHeaderHeight: %3.2f",paramHeaderHeight);
82 }
float paramHeaderHeight
id< Z6ContainedView > tableHead

◆ setViewForTail:()

- (void) setViewForTail: (UIView<Z6ContainedView> *)  tailView

Definition at line 83 of file U3ParameterTableView.m.

83  : (UIView<Z6ContainedView> *) tailView
84 {
85  tableTail = tailView;
86  paramFooterHeight = [tailView heightRequirement];
87  NSLog(@"U3ParameterTableView.setViewForTail: paramFooterHeight: %3.2f", paramFooterHeight);
88 }
UIView< Z6ContainedView > * tableTail
float paramFooterHeight

◆ tableView:cellForRowAtIndexPath:()

- (UITableViewCell *) tableView: (UITableView *)  tableView
cellForRowAtIndexPath: (NSIndexPath *)  indexPath 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 235 of file U3ParameterTableView.m.

235  :(UITableView *)tableView
236  cellForRowAtIndexPath:(NSIndexPath *)indexPath
237 {
238  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"usda-parameters-menu"];
239  // NSLog(@"U3parameterTableView.tableCellForRow: %ld cell: %@", (long)[indexPath row], cell);
240  if (cell == nil) {
241  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"usda-parameters-menu"];
242 
243  cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
244  [cell.layer setCornerRadius:7.0f];
245  [cell.layer setMasksToBounds:YES];
246  [cell.layer setBorderWidth:1.0f];
247  }
248 
249  NSInteger nComponents = [[self givenParameters] count];
250 
251  if (nComponents > [indexPath row]) {
252 
253  NSObject *parameterObj = [[self givenParameters] objectAtIndex:[indexPath row]];
254  if ([NSStringFromClass([parameterObj class]) containsString:@"Dictionary"]) {
255  NSDictionary *focusNutritionComp = (NSDictionary *)parameterObj;
256  // NSLog(@"U3parameterTableView.table-cellForRow: %ld focusNutritionComp: %@", (long)[indexPath row], focusNutritionComp);
257  NSString *caption = [focusNutritionComp objectForKey:[Z5LocalDataController componentNameKey]];
258  NSMutableString *captionWithSpace = [[NSMutableString alloc] initWithString:caption];
259  if ([caption hasPrefix:@"Fat"]) {
260  [captionWithSpace insertString:@" " atIndex:3];
261  } else if ([caption hasPrefix:@"Vitamin"]) {
262  [captionWithSpace insertString:@" " atIndex:7];
263  }
264 
265  NSString *valueCaption = [focusNutritionComp objectForKey:[Z5LocalDataController componentValueKey]];
266  NSString *compoTypeClass = NSStringFromClass([valueCaption class]);
267 
268  NSString *detailCaption;
269  if ([compoTypeClass isEqualToString:@"HKQuantity"]) {
270  // NSLog(@"U3parameterTableView.didSelectPickerRow: compo-class: %@", compoTypeClass);
271  HKQuantity* hkq = (HKQuantity *)valueCaption;
272  // NSLog(@"U3parameterTableView.tableCellForRow: desc: %@", hkq.description);
273  // cell.detailTextLabel.text = hkq.description;
274  detailCaption = hkq.description;
275  } else {
276  // cell.detailTextLabel.text = valueCaption;
277  detailCaption = valueCaption;
278  }
279  // NSLog(@"U3parameterTableView.table-cellForRow: caption/valueCaption: %@/%@", caption, valueCaption);
280  [Z5DataController labelizeCell:cell withText:captionWithSpace inColor:[UIColor redColor] andDetail:detailCaption];
281 
282  NSNumber *authoStat = [focusNutritionComp objectForKey:[Z5LocalDataController componentAuthorityKey]];
283  // NSLog(@"U3parameterTableView: authoStat: %@", authoStat);
284  UIColor *authorityColor = [Z5LocalDataController colorForAuthority:authoStat];
285  [cell setBackgroundColor:authorityColor];
286  } else if ([@"Meal" isEqualToString:NSStringFromClass([parameterObj class]) ]) {
287  Meal *focusNutritionMeal = (Meal *)parameterObj;
288  NSDate *mealDate = [focusNutritionMeal orderDate];
289  NSString *mealDateStr = [mDateFormatter stringFromDate:mealDate];
290  // NSString *caption = @"jklegr";
291  NSString *detailCaption = @"none";
292  [Z5DataController labelizeCell:cell withText:mealDateStr inColor:[UIColor orangeColor] andDetail:detailCaption];
293  } else {
294  NSLog(@"U3ParameterTableView.cellForRow: parameter-obj class: %@", NSStringFromClass([parameterObj class]));
295  }
296  } else if (0 == nComponents) {
297  cell.textLabel.text = @"no parameter";
298  }
299 
300  // NSLog(@"U3parameterTableView.tableCellForRow: %ld return cell: %@", (long)[indexPath row], cell);
301  return cell;
302 }
UIColor * colorForAuthority:(NSNumber *authorityValue)
Singleton interface to both core and remote data sources.
NSDate * orderDate
void labelizeCell:withText:inColor:andDetail:(UITableViewCell *targCell, [withText] NSString *txt, [inColor] UIColor *color, [andDetail] NSString *detailTxt)

◆ tableView:didSelectRowAtIndexPath:()

- (void) tableView: (UITableView *)  tableView
didSelectRowAtIndexPath: (NSIndexPath *)  indexPath 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 213 of file U3ParameterTableView.m.

213  :(UITableView *)tableView
214 didSelectRowAtIndexPath:(NSIndexPath *)indexPath
215 {
216  NSLog(@"U3ParameterTableView.didSelectRowAtIndexPath: %ld", (long)indexPath.row);
217 
218  [[self givenContainer] didSelectParameterRow:indexPath];
219 }

◆ tableView:heightForFooterInSection:()

- (CGFloat) tableView: (UITableView *)  tableView
heightForFooterInSection: (NSInteger)  section 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 318 of file U3ParameterTableView.m.

318  :(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
319 
320  // height of the footer
321  // this needs to be set, otherwise the height is zero and no footer will show
322  // NSLog(@"U3ParameterTableView.heightForFooterInSection: %3.2f", paramFooterHeight);
323  // return [tableTail heightRequirement];
324  return paramFooterHeight;
325 }
float paramFooterHeight

◆ tableView:heightForHeaderInSection:()

- (CGFloat) tableView: (UITableView *)  tableView
heightForHeaderInSection: (NSInteger)  section 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 304 of file U3ParameterTableView.m.

304  :(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
305 
306  // height of the section header
307  // this needs to be set, otherwise the height is zero and no footer will show
308  // NSLog(@"U3ParameterTableView.heightForHeaderInSection: %3.2f", paramHeaderHeight);
309  return paramHeaderHeight;
310 }
float paramHeaderHeight

◆ tableView:numberOfRowsInSection:()

- (NSInteger) tableView: (UITableView *)  tableView
numberOfRowsInSection: (NSInteger)  section 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 227 of file U3ParameterTableView.m.

227  :(UITableView *)tableView
228  numberOfRowsInSection:(NSInteger)section
229 {
230  askedOnce = NO; // initialize somehow
231  NSInteger ret = [[self givenParameters] count];
232  NSLog(@"U3ParameterTableView.numberOfRowsInSection: # of rows in table: %ld", (long)ret);
233  return ret;
234 }

◆ tableView:viewForFooterInSection:()

- (UIView *) tableView: (UITableView *)  tableView
viewForFooterInSection: (NSInteger)  section 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 327 of file U3ParameterTableView.m.

327  :(UITableView *)tableView viewForFooterInSection:(NSInteger)section
328 {
329  return (UIView *)tableTail;
330 }
UIView< Z6ContainedView > * tableTail

◆ tableView:viewForHeaderInSection:()

- (UIView *) tableView: (UITableView *)  tableView
viewForHeaderInSection: (NSInteger)  section 
implementation

Reimplemented in U3MenuChoicesTableView.

Definition at line 312 of file U3ParameterTableView.m.

312  :(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
313 
314  // NSLog(@"U3ParameterTableView.viewForHeaderInSecion: %ld", section);
315  return (UIView *)tableHead;
316 }
id< Z6ContainedView > tableHead

◆ update:()

- (void) update: (NSArray<NSDictionary *> *)  components

Definition at line 94 of file U3ParameterTableView.m.

94  :(NSArray<NSDictionary *> *)components
95 {
96  NSLog(@"U3ParameterTableView.update: components: %@", components);
97 
98  [[self givenParameters] removeAllObjects];
99  if (components) {
100  for (NSDictionary *givenPrmDict in components) {
101  NSLog(@"U3ParameterTableView.update: given-parameter-dictionary: %@", givenPrmDict);
102  }
103  [[self givenParameters] addObjectsFromArray:components];
104  }
105  [self reloadData];
106 
107  NSMutableArray<NSDictionary *> *givParam = [self givenParameters];
108  [[self givenContainer] updatedParameterArray:givParam];
109  [[self givenContainer] resizeParameterFrame];
110 }

◆ updateParameter:()

- (void) updateParameter: (NSDictionary *)  newComponentSpecDict

Definition at line 134 of file U3ParameterTableView.m.

134  : (NSDictionary *)newComponentSpecDict
135 {
136  NSString *updateParamName = [newComponentSpecDict objectForKey:[Z5LocalDataController componentNameKey]];
137  for (NSUInteger index = 0; index < [[self givenParameters] count]; index++) {
138  NSDictionary *paramListed = [[self givenParameters] objectAtIndex:index];
139  NSString *listedParamName = [paramListed objectForKey:[Z5LocalDataController componentNameKey]];
140  if ([updateParamName isEqualToString:listedParamName]) {
141  [[self givenParameters] replaceObjectAtIndex:index withObject:newComponentSpecDict];
142  break;
143  }
144  }
145 
146  [[self givenContainer] resizeParameterFrame];
147  NSMutableArray<NSDictionary *> *givParam = [self givenParameters];
148  [[self givenContainer] updatedParameterArray:givParam];
149 }
NSMutableDictionary * newComponentSpecDict

Property Documentation

◆ givenContainer

- (id<U3ParameterTableDelegate>) givenContainer
readwritenonatomicstrong

Definition at line 17 of file U3ParameterTableView.h.

◆ givenParameters

- (NSMutableArray<NSDictionary *>*) givenParameters
readwritenonatomicstrong

Definition at line 16 of file U3ParameterTableView.h.


The documentation for this class was generated from the following files: