@@ -197,9 +197,9 @@ - (NSIndexPath *)indexPathForRowWithSubview:(UIView *)subview
197197 return [self .tableView indexPathForRowAtPoint: point];
198198}
199199
200- - (CGFloat)heightForCellWithIdentifier : (NSString *)identifier
201- text : (NSString *)text
202- limitedToNumberOfLines : (NSInteger )numberOfLines
200+ - (CGFloat)heightForResizableCellWithIdentifier : (NSString *)identifier
201+ text : (NSString *)text
202+ limitedToNumberOfLines : (NSInteger )numberOfLines
203203{
204204 static NSMutableDictionary * cache;
205205 static dispatch_once_t onceToken;
@@ -212,7 +212,7 @@ - (CGFloat)heightForCellWithIdentifier:(NSString *)identifier
212212 NSDictionary * cachedValues = cache[uniqueCellIdenfier];
213213 CGFloat minimumHeight;
214214 CGSize sizeDifference;
215- UILabel * label ;
215+ UIView * resizableView ;
216216
217217 if (!cachedValues)
218218 {
@@ -221,35 +221,51 @@ - (CGFloat)heightForCellWithIdentifier:(NSString *)identifier
221221 NSAssert ([cell conformsToProtocol: @protocol (AMBResizableCell)], @" Cell doesn't conform to the AMBResizableCell protocol." );
222222
223223 minimumHeight = cell.frame .size .height ;
224- label = cell.resizableLabel ;
224+ resizableView = cell.resizableView ;
225225 sizeDifference = cell.frame .size ;
226- sizeDifference.width -= label .frame .size .width ;
227- sizeDifference.height -= label .frame .size .height ;
226+ sizeDifference.width -= resizableView .frame .size .width ;
227+ sizeDifference.height -= resizableView .frame .size .height ;
228228
229- NSAssert (label , @" No resizableLabel set in cell" );
229+ NSAssert (resizableView , @" No resizableView set in cell" );
230230
231231 cachedValues = @{@" minimumHeight" : @(minimumHeight),
232232 @" sizeDifference" : [NSValue valueWithCGSize: sizeDifference],
233- @" label " : label };
233+ @" resizableView " : resizableView };
234234 cache[uniqueCellIdenfier] = cachedValues;
235235 }
236236 else
237237 {
238238 minimumHeight = ((NSNumber *)cachedValues[@" minimumHeight" ]).floatValue ;
239239 sizeDifference = ((NSNumber *)cachedValues[@" sizeDifference" ]).CGSizeValue ;
240- label = cachedValues[@" label " ];
240+ resizableView = cachedValues[@" resizableView " ];
241241 }
242242
243- label.text = text;
244- CGRect labelBounds = CGRectMake (0.0 ,
245- 0.0 ,
246- self.tableView .frame .size .width - sizeDifference.width ,
247- CGFLOAT_MAX);
248- CGRect rect = [label textRectForBounds: labelBounds
249- limitedToNumberOfLines: numberOfLines];
243+ CGFloat heightThatFits = 0.0 ;
244+ CGRect frame = CGRectMake (0.0 ,
245+ 0.0 ,
246+ self.tableView .frame .size .width - sizeDifference.width ,
247+ CGFLOAT_MAX);
248+ if ([resizableView isKindOfClass: [UILabel class ]])
249+ {
250+ UILabel * resizableLabel = (UILabel *)resizableView;
251+ resizableLabel.text = text;
252+ heightThatFits = [resizableLabel textRectForBounds: frame
253+ limitedToNumberOfLines: numberOfLines].size .height ;
254+ }
255+ else if ([resizableView isKindOfClass: [UITextView class ]])
256+ {
257+ UITextView * resizableTextView = (UITextView *)resizableView;
258+ resizableTextView.text = text;
259+ heightThatFits = [resizableTextView sizeThatFits: frame.size].height ;
260+ // TODO: Adjust to numberOfLines
261+ }
262+ else
263+ {
264+ NSAssert (false , @" The provided resizableView class '%@ ' is not supported" , NSStringFromClass ([resizableView class ]));
265+ }
250266
251267 CGFloat cellSeparatorHeight = (self.tableView .separatorStyle == UITableViewCellSeparatorStyleNone) ? 0.0 : 1.0 ;
252- return MAX (rect. size . height + sizeDifference.height + cellSeparatorHeight,
268+ return MAX (heightThatFits + sizeDifference.height + cellSeparatorHeight,
253269 minimumHeight);
254270}
255271
0 commit comments