@aks-dev/easyui 1.0.31 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,537 @@
1
+ //
2
+ // UITableView+SDAutoTableViewCellHeight.m
3
+ // SDAutoLayout 测试 Demo
4
+ //
5
+ // Created by aier on 15/11/1.
6
+ // Copyright © 2015年 gsd. All rights reserved.
7
+ //
8
+
9
+ /*
10
+
11
+ *********************************************************************************
12
+ * *
13
+ * 在您使用此自动布局库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 *
14
+ * 帮您解决问题。 *
15
+ * QQ : 2689718696(gsdios) *
16
+ * Email : gsdios@126.com *
17
+ * GitHub: https://github.com/gsdios *
18
+ * 新浪微博:GSD_iOS *
19
+ * *
20
+ *********************************************************************************
21
+
22
+ */
23
+
24
+ #import "UITableView+SDAutoTableViewCellHeight.h"
25
+ #import <objc/runtime.h>
26
+
27
+ @interface SDCellAutoHeightManager ()
28
+
29
+ @property (nonatomic, weak) UITableView *modelTableview;
30
+
31
+ @end
32
+
33
+ @implementation SDCellAutoHeightManager
34
+ {
35
+ NSMutableDictionary *_cacheDictionary;
36
+ NSMutableDictionary *_modelCellsDict;
37
+ }
38
+
39
+ - (instancetype)init
40
+ {
41
+ if (self = [super init]) {
42
+ [self setup];
43
+ }
44
+ return self;
45
+ }
46
+
47
+ - (instancetype)initWithCellClass:(Class)cellClass tableView:(UITableView *)tableView
48
+ {
49
+ if (self = [super init]) {
50
+ [self setup];
51
+ self.modelTableview = tableView;
52
+ [self registerCellWithCellClass:cellClass];
53
+ }
54
+ return self;
55
+ }
56
+
57
+ - (instancetype)initWithCellClasses:(NSArray *)cellClassArray tableView:(UITableView *)tableView
58
+ {
59
+ if (self = [super init]) {
60
+ [self setup];
61
+ self.modelTableview = tableView;
62
+ [cellClassArray enumerateObjectsUsingBlock:^(Class obj, NSUInteger idx, BOOL *stop) {
63
+ [self registerCellWithCellClass:obj];
64
+ }];
65
+ }
66
+ return self;
67
+ }
68
+
69
+ - (void)setup
70
+ {
71
+ _cacheDictionary = [NSMutableDictionary new];
72
+ _modelCellsDict = [NSMutableDictionary new];
73
+ }
74
+
75
+ - (void)registerCellWithCellClass:(Class)cellClass
76
+ {
77
+ [_modelTableview registerClass:cellClass forCellReuseIdentifier:NSStringFromClass(cellClass)];
78
+ self.modelCell = [_modelTableview dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
79
+
80
+ if (!self.modelCell.contentView.subviews.count) {
81
+ NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@.nib", NSStringFromClass(cellClass)] ofType:nil];
82
+ if (path) {
83
+ self.modelCell = nil;
84
+ [_modelTableview registerNib:[UINib nibWithNibName:NSStringFromClass(cellClass) bundle:nil] forCellReuseIdentifier:NSStringFromClass(cellClass)];
85
+ self.modelCell = [_modelTableview dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
86
+ }
87
+ }
88
+ if (self.modelCell) {
89
+ [_modelCellsDict setObject:self.modelCell forKey:NSStringFromClass(cellClass)];
90
+ }
91
+ }
92
+
93
+ + (instancetype)managerWithCellClass:(Class)cellClass tableView:(UITableView *)tableView
94
+ {
95
+ SDCellAutoHeightManager *manager = [[self alloc] initWithCellClass:cellClass tableView:tableView];
96
+ return manager;
97
+ }
98
+
99
+ - (UITableViewCell *)modelCell
100
+ {
101
+ if (_modelCell.contentView.tag != kSDModelCellTag) {
102
+ _modelCell.contentView.tag = kSDModelCellTag;
103
+ }
104
+ return _modelCell;
105
+ }
106
+
107
+ - (NSDictionary *)heightCacheDict
108
+ {
109
+ return _cacheDictionary;
110
+ }
111
+
112
+ - (void)clearHeightCache
113
+ {
114
+ [_cacheDictionary removeAllObjects];
115
+ [_subviewFrameCacheDict removeAllObjects];
116
+ }
117
+
118
+ - (NSString *)cacheKeyForIndexPath:(NSIndexPath *)indexPath
119
+ {
120
+ return [NSString stringWithFormat:@"%ld-%ld", (long)indexPath.section, (long)indexPath.row];
121
+ }
122
+
123
+ - (void)clearHeightCacheOfIndexPaths:(NSArray *)indexPaths
124
+ {
125
+ [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
126
+ NSString *cacheKey = [self cacheKeyForIndexPath:indexPath];
127
+ [_cacheDictionary removeObjectForKey:cacheKey];
128
+ [_subviewFrameCacheDict removeObjectForKey:cacheKey];
129
+ }];
130
+ }
131
+
132
+ - (void)deleteThenResetHeightCache:(NSIndexPath *)indexPathToDelete
133
+ {
134
+
135
+ NSString *cacheKey = [self cacheKeyForIndexPath:indexPathToDelete];
136
+ [_cacheDictionary removeObjectForKey:cacheKey];
137
+ [_subviewFrameCacheDict removeObjectForKey:cacheKey];
138
+
139
+ long sectionOfToDeleteItem = indexPathToDelete.section;
140
+ long rowOfToDeleteItem = indexPathToDelete.row;
141
+ NSMutableDictionary *tempHeightCacheDict = [NSMutableDictionary new];
142
+ NSMutableDictionary *tempFrameCacheDict = [NSMutableDictionary new];
143
+ for (NSString *key in _cacheDictionary.allKeys) {
144
+ NSArray *res = [key componentsSeparatedByString:@"-"];
145
+ long section = [res.firstObject integerValue];
146
+ long row = [res.lastObject integerValue];
147
+ if (section == sectionOfToDeleteItem && row > rowOfToDeleteItem) {
148
+ NSNumber *heightCache = _cacheDictionary[key];
149
+ NSArray *frameCache = _subviewFrameCacheDict[key];
150
+ NSString *newKey = [NSString stringWithFormat:@"%ld-%ld", section, (row - 1)];
151
+ [tempHeightCacheDict setValue:heightCache forKey:newKey];
152
+ [tempFrameCacheDict setValue:frameCache forKey:newKey];
153
+ [_cacheDictionary removeObjectForKey:key];
154
+ [_subviewFrameCacheDict removeObjectForKey:key];
155
+ }
156
+ }
157
+ [_cacheDictionary addEntriesFromDictionary:tempHeightCacheDict];
158
+ [_subviewFrameCacheDict addEntriesFromDictionary:tempFrameCacheDict];
159
+
160
+ }
161
+
162
+ - (void)insertNewDataAtTheBeginingOfSection:(NSInteger)section newDataCount:(NSInteger)count
163
+ {
164
+ NSMutableDictionary *tempHeightCacheDict = [NSMutableDictionary new];
165
+ NSMutableDictionary *tempFrameCacheDict = [NSMutableDictionary new];
166
+ for (NSString *key in _cacheDictionary.allKeys) {
167
+ NSArray *res = [key componentsSeparatedByString:@"-"];
168
+ long originalSection = [res.firstObject integerValue];
169
+ long row = [res.lastObject integerValue];
170
+ if (originalSection == section) {
171
+ NSNumber *heightCache = _cacheDictionary[key];
172
+ NSArray *frameCache = _subviewFrameCacheDict[key];
173
+ NSString *newKey = [NSString stringWithFormat:@"%ld-%ld", originalSection, (row + count)];
174
+ [tempHeightCacheDict setValue:heightCache forKey:newKey];
175
+ [tempFrameCacheDict setValue:frameCache forKey:newKey];
176
+ [_cacheDictionary removeObjectForKey:key];
177
+ [_subviewFrameCacheDict removeObjectForKey:key];
178
+ }
179
+ }
180
+ [_cacheDictionary addEntriesFromDictionary:tempHeightCacheDict];
181
+ [_subviewFrameCacheDict addEntriesFromDictionary:tempFrameCacheDict];
182
+ }
183
+
184
+ - (void)insertNewDataAtIndexPaths:(NSArray *)indexPaths
185
+ {
186
+ NSMutableDictionary *sectionsdict = [NSMutableDictionary new];
187
+ for (NSIndexPath *indexPath in indexPaths) {
188
+ NSString *sectionkey = [@(indexPath.section) stringValue];
189
+ if (![sectionsdict objectForKey:sectionkey]) {
190
+ [sectionsdict setValue:[NSMutableArray new] forKey:sectionkey];
191
+ }
192
+ NSMutableArray *arr = sectionsdict[sectionkey];
193
+ [arr addObject:indexPath];
194
+ }
195
+ for (NSString *sectionkey in sectionsdict.allKeys) {
196
+ NSMutableArray *tempHeightCaches = [NSMutableArray new];
197
+ NSMutableArray *tempFrameCaches = [NSMutableArray new];
198
+ NSInteger section = [sectionkey integerValue];
199
+ NSInteger rowCount = [self.modelTableview numberOfRowsInSection:section];
200
+ if (rowCount <= 0) {
201
+ continue;
202
+ } else {
203
+ for (int i = 0; i < rowCount; i++) {
204
+ [tempHeightCaches addObject:[NSNull null]];
205
+ [tempFrameCaches addObject:[NSNull null]];
206
+ }
207
+ }
208
+
209
+ for (NSString *key in _cacheDictionary.allKeys) {
210
+ NSArray *res = [key componentsSeparatedByString:@"-"];
211
+ long originalSection = [res.firstObject integerValue];
212
+ long row = [res.lastObject integerValue];
213
+ if (originalSection == section) {
214
+ NSNumber *heightCache = _cacheDictionary[key];
215
+ NSArray *frameCache = _subviewFrameCacheDict[key];
216
+ [tempHeightCaches setObject:heightCache atIndexedSubscript:row];
217
+ [tempFrameCaches setObject:frameCache atIndexedSubscript:row];
218
+ [_cacheDictionary removeObjectForKey:key];
219
+ [_subviewFrameCacheDict removeObjectForKey:key];
220
+ }
221
+ }
222
+ NSMutableArray *objsToInsert = [NSMutableArray new];
223
+ NSMutableIndexSet *indexSet = [NSMutableIndexSet new];
224
+ NSArray *indexPaths = sectionsdict[sectionkey];
225
+ [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *obj, NSUInteger idx, BOOL *stop) {
226
+ [objsToInsert addObject:[NSNull null]];
227
+ [indexSet addIndex:obj.row];
228
+ }];
229
+ [tempHeightCaches insertObjects:objsToInsert atIndexes:indexSet];
230
+ [tempFrameCaches insertObjects:objsToInsert atIndexes:indexSet];
231
+ [tempHeightCaches enumerateObjectsUsingBlock:^(NSNumber *heightCache, NSUInteger idx, BOOL *stop) {
232
+ if (![heightCache isKindOfClass:[NSNull class]]) {
233
+ NSString *key = [NSString stringWithFormat:@"%zd-%zd", section, idx];
234
+ [_cacheDictionary setValue:heightCache forKey:key];
235
+ [_subviewFrameCacheDict setValue:[tempFrameCaches objectAtIndex:idx] forKey:key];
236
+ }
237
+ }];
238
+ }
239
+ }
240
+
241
+ - (NSNumber *)heightCacheForIndexPath:(NSIndexPath *)indexPath
242
+ {
243
+ /*
244
+ 如果程序卡在了这里很可能是由于你用了“dequeueReusableCellWithIdentifier:forIndexPath:”方法来重用cell,换成““dequeueReusableCellWithIdentifier:”(不带IndexPath)方法即可解决
245
+ */
246
+ NSString *cacheKey = [self cacheKeyForIndexPath:indexPath];
247
+ return (NSNumber *)[_cacheDictionary objectForKey:cacheKey];
248
+ }
249
+
250
+ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath
251
+ {
252
+
253
+ NSNumber *cacheHeight = [self heightCacheForIndexPath:indexPath];
254
+ if (cacheHeight) {
255
+ return [cacheHeight floatValue];
256
+ } else {
257
+ if (!self.modelCell) {
258
+ return 0;
259
+ }
260
+
261
+ if (self.modelTableview && self.modelTableview != self.modelCell.sd_tableView) {
262
+ self.modelCell.sd_tableView = self.modelTableview;
263
+ }
264
+ self.modelCell.sd_indexPath = indexPath;
265
+
266
+ if (model && keyPath) {
267
+ [self.modelCell setValue:model forKey:keyPath];
268
+ } else if (self.cellDataSetting) {
269
+ self.cellDataSetting(self.modelCell);
270
+ }
271
+
272
+
273
+ #ifdef SDDebugWithAssert
274
+ /*
275
+ 如果程序卡在了这里说明你的cell还没有调用“setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin”方法或者你传递的bottomView为nil,请检查并修改。例:
276
+
277
+ //注意:bottomView不能为nil
278
+ [cell setupAutoHeightWithBottomView:bottomView bottomMargin:bottomMargin];
279
+ */
280
+ NSAssert(self.modelCell.sd_bottomViewsArray.count, @">>>>>> 你的cell还没有调用“setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin”方法或者你传递的bottomView为nil,请检查并修改");
281
+
282
+ #endif
283
+
284
+ [self.modelCell.contentView layoutSubviews];
285
+ NSString *cacheKey = [self cacheKeyForIndexPath:indexPath];
286
+ [_cacheDictionary setObject:@(self.modelCell.autoHeight) forKey:cacheKey];
287
+
288
+
289
+ if (self.modelCell.sd_indexPath && self.modelCell.sd_tableView) {
290
+ if (self.modelCell.contentView.shouldReadjustFrameBeforeStoreCache) {
291
+ self.modelCell.contentView.height_sd = self.modelCell.autoHeight;
292
+ [self.modelCell.contentView layoutSubviews];
293
+ }
294
+ [self.modelCell.contentView.autoLayoutModelsArray enumerateObjectsUsingBlock:^(SDAutoLayoutModel *model, NSUInteger idx, BOOL *stop) {
295
+ [self.modelTableview.cellAutoHeightManager setSubviewFrameCache:model.needsAutoResizeView.frame WithIndexPath:self.modelCell.sd_indexPath];
296
+ }];
297
+ }
298
+
299
+
300
+ return self.modelCell.autoHeight;
301
+ }
302
+ }
303
+
304
+ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass
305
+ {
306
+ if (![self.modelCell isKindOfClass:cellClass]) {
307
+ self.modelCell = nil;
308
+ self.modelCell = [_modelCellsDict objectForKey:NSStringFromClass(cellClass)];
309
+ if (!self.modelCell) {
310
+ [self registerCellWithCellClass:cellClass];
311
+ }
312
+ _modelCell.contentView.tag = kSDModelCellTag;
313
+ }
314
+ if (self.modelCell.contentView.width_sd != self.contentViewWidth) {
315
+ _modelCell.contentView.width_sd = self.contentViewWidth;
316
+ }
317
+ return [self cellHeightForIndexPath:indexPath model:model keyPath:keyPath];
318
+ }
319
+
320
+ - (void)setContentViewWidth:(CGFloat)contentViewWidth
321
+ {
322
+ if (_contentViewWidth == contentViewWidth) return;
323
+
324
+ CGFloat lastContentViewWidth = _contentViewWidth;
325
+ _contentViewWidth = contentViewWidth;
326
+
327
+ self.modelCell.contentView.width_sd = self.contentViewWidth;
328
+
329
+ if (lastContentViewWidth > 0) {
330
+ [_subviewFrameCacheDict removeAllObjects];
331
+ dispatch_async(dispatch_get_main_queue(), ^{
332
+ [self clearHeightCache];
333
+ [self.modelTableview reloadData];
334
+ });
335
+ }
336
+ }
337
+
338
+
339
+ - (void)setSubviewFrameCache:(CGRect)rect WithIndexPath:(NSIndexPath *)indexPath
340
+ {
341
+ if (!self.subviewFrameCacheDict) {
342
+ self.subviewFrameCacheDict = [NSMutableDictionary new];
343
+ }
344
+ NSString *cacheKey = [self cacheKeyForIndexPath:indexPath];
345
+ NSMutableArray *caches = [self.subviewFrameCacheDict objectForKey:cacheKey];
346
+ if (!caches) {
347
+ caches = [NSMutableArray new];
348
+ [self.subviewFrameCacheDict setValue:caches forKey:cacheKey];
349
+ }
350
+ [caches addObject:[NSValue valueWithCGRect:rect]];
351
+ }
352
+
353
+ - (NSMutableArray *)subviewFrameCachesWithIndexPath:(NSIndexPath *)indexPath
354
+ {
355
+ NSString *cacheKey = [self cacheKeyForIndexPath:indexPath];
356
+ return [self.subviewFrameCacheDict valueForKey:cacheKey];
357
+ }
358
+
359
+ @end
360
+
361
+
362
+ @implementation UITableView (SDAutoTableViewCellHeight)
363
+
364
+ + (void)load {
365
+ static dispatch_once_t onceToken;
366
+ dispatch_once(&onceToken, ^{
367
+
368
+ NSArray *selStringsArray = @[@"reloadData", @"reloadRowsAtIndexPaths:withRowAnimation:", @"deleteRowsAtIndexPaths:withRowAnimation:", @"insertRowsAtIndexPaths:withRowAnimation:"];
369
+
370
+ [selStringsArray enumerateObjectsUsingBlock:^(NSString *selString, NSUInteger idx, BOOL *stop) {
371
+ NSString *mySelString = [@"sd_" stringByAppendingString:selString];
372
+
373
+ Method originalMethod = class_getInstanceMethod(self, NSSelectorFromString(selString));
374
+ Method myMethod = class_getInstanceMethod(self, NSSelectorFromString(mySelString));
375
+ method_exchangeImplementations(originalMethod, myMethod);
376
+ }];
377
+ });
378
+ }
379
+
380
+ - (void)sd_reloadData
381
+ {
382
+ if (!self.cellAutoHeightManager.shouldKeepHeightCacheWhenReloadingData) {
383
+ [self.cellAutoHeightManager clearHeightCache];
384
+ }
385
+ [self sd_reloadData];
386
+ self.cellAutoHeightManager.shouldKeepHeightCacheWhenReloadingData = NO;
387
+ }
388
+
389
+ - (void)sd_reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
390
+ {
391
+ [self.cellAutoHeightManager clearHeightCacheOfIndexPaths:indexPaths];
392
+ [self sd_reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];
393
+ }
394
+
395
+ - (void)sd_deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
396
+ {
397
+ for (NSIndexPath *indexPath in indexPaths) {
398
+ [self.cellAutoHeightManager deleteThenResetHeightCache:indexPath];
399
+ }
400
+ [self sd_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];
401
+ }
402
+
403
+
404
+ - (void)sd_insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
405
+ {
406
+ [self.cellAutoHeightManager insertNewDataAtIndexPaths:indexPaths];
407
+ [self sd_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];
408
+ }
409
+
410
+ /*
411
+ * 下一步即将实现的功能
412
+
413
+ - (void)sd_moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
414
+ {
415
+ [self sd_moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
416
+ }
417
+
418
+ */
419
+
420
+ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass contentViewWidth:(CGFloat)contentViewWidth
421
+ {
422
+ self.cellAutoHeightManager.modelTableview = self;
423
+
424
+ self.cellAutoHeightManager.contentViewWidth = contentViewWidth;
425
+
426
+ return [self.cellAutoHeightManager cellHeightForIndexPath:indexPath model:model keyPath:keyPath cellClass:cellClass];
427
+ }
428
+
429
+ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellClass:(__unsafe_unretained Class)cellClass cellContentViewWidth:(CGFloat)width cellDataSetting:(AutoCellHeightDataSettingBlock)cellDataSetting
430
+ {
431
+
432
+ self.cellDataSetting = cellDataSetting;
433
+
434
+ return [self cellHeightForIndexPath:indexPath model:nil keyPath:nil cellClass:cellClass contentViewWidth:width];
435
+ }
436
+
437
+ - (void)reloadDataWithExistedHeightCache
438
+ {
439
+ self.cellAutoHeightManager.shouldKeepHeightCacheWhenReloadingData = YES;
440
+ [self reloadData];
441
+ }
442
+
443
+ - (void)reloadDataWithInsertingDataAtTheBeginingOfSection:(NSInteger)section newDataCount:(NSInteger)count
444
+ {
445
+ self.cellAutoHeightManager.shouldKeepHeightCacheWhenReloadingData = YES;
446
+ [self.cellAutoHeightManager insertNewDataAtTheBeginingOfSection:section newDataCount:count];
447
+ [self reloadData];
448
+ }
449
+
450
+ - (void)reloadDataWithInsertingDataAtTheBeginingOfSections:(NSArray *)sectionNumsArray newDataCounts:(NSArray *)dataCountsArray
451
+ {
452
+ self.cellAutoHeightManager.shouldKeepHeightCacheWhenReloadingData = YES;
453
+ [sectionNumsArray enumerateObjectsUsingBlock:^(NSNumber *num, NSUInteger idx, BOOL *stop) {
454
+ int section = [num intValue];
455
+ int dataCountForSection = [dataCountsArray[idx] intValue];
456
+ [self.cellAutoHeightManager insertNewDataAtTheBeginingOfSection:section newDataCount:dataCountForSection];
457
+ }];
458
+ [self reloadData];
459
+ }
460
+
461
+ - (CGFloat)cellsTotalHeight
462
+ {
463
+ CGFloat h = 0;
464
+ if (!self.cellAutoHeightManager.heightCacheDict.count) {
465
+ [self reloadData];
466
+ }
467
+ NSArray *values = [self.cellAutoHeightManager.heightCacheDict allValues];
468
+ for (NSNumber *number in values) {
469
+ h += [number floatValue];
470
+ }
471
+ return h;
472
+ }
473
+
474
+ - (SDCellAutoHeightManager *)cellAutoHeightManager
475
+ {
476
+
477
+ SDCellAutoHeightManager *cellAutoHeightManager = objc_getAssociatedObject(self, _cmd);
478
+
479
+ if (!cellAutoHeightManager) {
480
+
481
+ cellAutoHeightManager = [[SDCellAutoHeightManager alloc] init];
482
+
483
+ [self setCellAutoHeightManager:cellAutoHeightManager];
484
+ }
485
+
486
+ return cellAutoHeightManager;
487
+ }
488
+
489
+ - (void)setCellAutoHeightManager:(SDCellAutoHeightManager *)cellAutoHeightManager
490
+ {
491
+ objc_setAssociatedObject(self, @selector(cellAutoHeightManager), cellAutoHeightManager, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
492
+ }
493
+
494
+ - (void)setCellDataSetting:(AutoCellHeightDataSettingBlock)cellDataSetting
495
+ {
496
+ self.cellAutoHeightManager.cellDataSetting = cellDataSetting;
497
+ }
498
+
499
+ - (AutoCellHeightDataSettingBlock)cellDataSetting
500
+ {
501
+ return self.cellAutoHeightManager.cellDataSetting;
502
+ }
503
+
504
+ @end
505
+
506
+
507
+ @implementation UITableViewController (SDTableViewControllerAutoCellHeight)
508
+
509
+ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellContentViewWidth:(CGFloat)width
510
+ {
511
+ return [self cellHeightForIndexPath:indexPath cellContentViewWidth:width tableView:self.tableView];
512
+ }
513
+
514
+ @end
515
+
516
+ @implementation NSObject (SDAnyObjectAutoCellHeight)
517
+
518
+ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellContentViewWidth:(CGFloat)width tableView:(UITableView *)tableView
519
+ {
520
+ tableView.cellAutoHeightManager.modelTableview = tableView;
521
+
522
+ if (tableView.cellAutoHeightManager.contentViewWidth != width) {
523
+ tableView.cellAutoHeightManager.contentViewWidth = width;
524
+ }
525
+ if ([tableView.cellAutoHeightManager heightCacheForIndexPath:indexPath]) {
526
+ return [[tableView.cellAutoHeightManager heightCacheForIndexPath:indexPath] floatValue];
527
+ }
528
+ UITableViewCell *cell = [tableView.dataSource tableView:tableView cellForRowAtIndexPath:indexPath];
529
+ tableView.cellAutoHeightManager.modelCell = cell;
530
+ if (cell.contentView.width_sd != width) {
531
+ cell.contentView.width_sd = width;
532
+ }
533
+ return [[tableView cellAutoHeightManager] cellHeightForIndexPath:indexPath model:nil keyPath:nil];
534
+ }
535
+
536
+ @end
537
+