Repository: forkingdog/UITableView-FDTemplateLayoutCell Branch: master Commit: c624e4db4c6b Files: 41 Total size: 137.3 KB Directory structure: gitextract_z1fhkhrn/ ├── .gitignore ├── Classes/ │ ├── UITableView+FDIndexPathHeightCache.h │ ├── UITableView+FDIndexPathHeightCache.m │ ├── UITableView+FDKeyedHeightCache.h │ ├── UITableView+FDKeyedHeightCache.m │ ├── UITableView+FDTemplateLayoutCell.h │ ├── UITableView+FDTemplateLayoutCell.m │ ├── UITableView+FDTemplateLayoutCellDebug.h │ └── UITableView+FDTemplateLayoutCellDebug.m ├── Demo/ │ ├── Demo/ │ │ ├── Base.lproj/ │ │ │ ├── LaunchScreen.xib │ │ │ └── Main.storyboard │ │ ├── FDAppDelegate.h │ │ ├── FDAppDelegate.m │ │ ├── FDFeedCell.h │ │ ├── FDFeedCell.m │ │ ├── FDFeedEntity.h │ │ ├── FDFeedEntity.m │ │ ├── FDFeedViewController.h │ │ ├── FDFeedViewController.m │ │ ├── Images.xcassets/ │ │ │ ├── AppIcon.appiconset/ │ │ │ │ └── Contents.json │ │ │ ├── breaddoge.imageset/ │ │ │ │ └── Contents.json │ │ │ ├── doge.imageset/ │ │ │ │ └── Contents.json │ │ │ ├── forkingdog.imageset/ │ │ │ │ └── Contents.json │ │ │ ├── phil.imageset/ │ │ │ │ └── Contents.json │ │ │ ├── sark.imageset/ │ │ │ │ └── Contents.json │ │ │ ├── sinojerk.imageset/ │ │ │ │ └── Contents.json │ │ │ └── sunnyxx.imageset/ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── data.json │ │ └── main.m │ └── Demo.xcodeproj/ │ ├── project.pbxproj │ └── project.xcworkspace/ │ └── contents.xcworkspacedata ├── FDTemplateCell.xcworkspace/ │ ├── contents.xcworkspacedata │ └── xcshareddata/ │ └── FDTemplateCell.xcscmblueprint ├── FDTemplateLayoutCell/ │ ├── FDTemplateLayoutCell.xcodeproj/ │ │ ├── project.pbxproj │ │ └── xcshareddata/ │ │ └── xcschemes/ │ │ └── FDTemplateLayoutCell.xcscheme │ └── FDTemplateLayoutcell/ │ ├── FDTemplateLayoutCell.h │ └── Info.plist ├── LICENSE ├── README.md └── UITableView+FDTemplateLayoutCell.podspec ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Xcode # build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa *.xcuserstate # CocoaPods # # We recommend against adding the Pods directory to your .gitignore. However # you should judge for yourself, the pros and cons are mentioned at: # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control # #Pods/ ================================================ FILE: Classes/UITableView+FDIndexPathHeightCache.h ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import @interface FDIndexPathHeightCache : NSObject // Enable automatically if you're using index path driven height cache @property (nonatomic, assign) BOOL automaticallyInvalidateEnabled; // Height cache - (BOOL)existsHeightAtIndexPath:(NSIndexPath *)indexPath; - (void)cacheHeight:(CGFloat)height byIndexPath:(NSIndexPath *)indexPath; - (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath; - (void)invalidateHeightAtIndexPath:(NSIndexPath *)indexPath; - (void)invalidateAllHeightCache; @end @interface UITableView (FDIndexPathHeightCache) /// Height cache by index path. Generally, you don't need to use it directly. @property (nonatomic, strong, readonly) FDIndexPathHeightCache *fd_indexPathHeightCache; @end @interface UITableView (FDIndexPathHeightCacheInvalidation) /// Call this method when you want to reload data but don't want to invalidate /// all height cache by index path, for example, load more data at the bottom of /// table view. - (void)fd_reloadDataWithoutInvalidateIndexPathHeightCache; @end ================================================ FILE: Classes/UITableView+FDIndexPathHeightCache.m ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import "UITableView+FDIndexPathHeightCache.h" #import typedef NSMutableArray *> FDIndexPathHeightsBySection; @interface FDIndexPathHeightCache () @property (nonatomic, strong) FDIndexPathHeightsBySection *heightsBySectionForPortrait; @property (nonatomic, strong) FDIndexPathHeightsBySection *heightsBySectionForLandscape; @end @implementation FDIndexPathHeightCache - (instancetype)init { self = [super init]; if (self) { _heightsBySectionForPortrait = [NSMutableArray array]; _heightsBySectionForLandscape = [NSMutableArray array]; } return self; } - (FDIndexPathHeightsBySection *)heightsBySectionForCurrentOrientation { return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) ? self.heightsBySectionForPortrait: self.heightsBySectionForLandscape; } - (void)enumerateAllOrientationsUsingBlock:(void (^)(FDIndexPathHeightsBySection *heightsBySection))block { block(self.heightsBySectionForPortrait); block(self.heightsBySectionForLandscape); } - (BOOL)existsHeightAtIndexPath:(NSIndexPath *)indexPath { [self buildCachesAtIndexPathsIfNeeded:@[indexPath]]; NSNumber *number = self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row]; return ![number isEqualToNumber:@-1]; } - (void)cacheHeight:(CGFloat)height byIndexPath:(NSIndexPath *)indexPath { self.automaticallyInvalidateEnabled = YES; [self buildCachesAtIndexPathsIfNeeded:@[indexPath]]; self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row] = @(height); } - (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath { [self buildCachesAtIndexPathsIfNeeded:@[indexPath]]; NSNumber *number = self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row]; #if CGFLOAT_IS_DOUBLE return number.doubleValue; #else return number.floatValue; #endif } - (void)invalidateHeightAtIndexPath:(NSIndexPath *)indexPath { [self buildCachesAtIndexPathsIfNeeded:@[indexPath]]; [self enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { heightsBySection[indexPath.section][indexPath.row] = @-1; }]; } - (void)invalidateAllHeightCache { [self enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection removeAllObjects]; }]; } - (void)buildCachesAtIndexPathsIfNeeded:(NSArray *)indexPaths { // Build every section array or row array which is smaller than given index path. [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) { [self buildSectionsIfNeeded:indexPath.section]; [self buildRowsIfNeeded:indexPath.row inExistSection:indexPath.section]; }]; } - (void)buildSectionsIfNeeded:(NSInteger)targetSection { [self enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { for (NSInteger section = 0; section <= targetSection; ++section) { if (section >= heightsBySection.count) { heightsBySection[section] = [NSMutableArray array]; } } }]; } - (void)buildRowsIfNeeded:(NSInteger)targetRow inExistSection:(NSInteger)section { [self enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { NSMutableArray *heightsByRow = heightsBySection[section]; for (NSInteger row = 0; row <= targetRow; ++row) { if (row >= heightsByRow.count) { heightsByRow[row] = @-1; } } }]; } @end @implementation UITableView (FDIndexPathHeightCache) - (FDIndexPathHeightCache *)fd_indexPathHeightCache { FDIndexPathHeightCache *cache = objc_getAssociatedObject(self, _cmd); if (!cache) { cache = [FDIndexPathHeightCache new]; objc_setAssociatedObject(self, _cmd, cache, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return cache; } @end // We just forward primary call, in crash report, top most method in stack maybe FD's, // but it's really not our bug, you should check whether your table view's data source and // displaying cells are not matched when reloading. static void __FD_TEMPLATE_LAYOUT_CELL_PRIMARY_CALL_IF_CRASH_NOT_OUR_BUG__(void (^callout)(void)) { callout(); } #define FDPrimaryCall(...) do {__FD_TEMPLATE_LAYOUT_CELL_PRIMARY_CALL_IF_CRASH_NOT_OUR_BUG__(^{__VA_ARGS__});} while(0) @implementation UITableView (FDIndexPathHeightCacheInvalidation) - (void)fd_reloadDataWithoutInvalidateIndexPathHeightCache { FDPrimaryCall([self fd_reloadData];); } + (void)load { // All methods that trigger height cache's invalidation SEL selectors[] = { @selector(reloadData), @selector(insertSections:withRowAnimation:), @selector(deleteSections:withRowAnimation:), @selector(reloadSections:withRowAnimation:), @selector(moveSection:toSection:), @selector(insertRowsAtIndexPaths:withRowAnimation:), @selector(deleteRowsAtIndexPaths:withRowAnimation:), @selector(reloadRowsAtIndexPaths:withRowAnimation:), @selector(moveRowAtIndexPath:toIndexPath:) }; for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) { SEL originalSelector = selectors[index]; SEL swizzledSelector = NSSelectorFromString([@"fd_" stringByAppendingString:NSStringFromSelector(originalSelector)]); Method originalMethod = class_getInstanceMethod(self, originalSelector); Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector); method_exchangeImplementations(originalMethod, swizzledMethod); } } - (void)fd_reloadData { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection removeAllObjects]; }]; } FDPrimaryCall([self fd_reloadData];); } - (void)fd_insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [sections enumerateIndexesUsingBlock:^(NSUInteger section, BOOL *stop) { [self.fd_indexPathHeightCache buildSectionsIfNeeded:section]; [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection insertObject:[NSMutableArray array] atIndex:section]; }]; }]; } FDPrimaryCall([self fd_insertSections:sections withRowAnimation:animation];); } - (void)fd_deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [sections enumerateIndexesUsingBlock:^(NSUInteger section, BOOL *stop) { [self.fd_indexPathHeightCache buildSectionsIfNeeded:section]; [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection removeObjectAtIndex:section]; }]; }]; } FDPrimaryCall([self fd_deleteSections:sections withRowAnimation:animation];); } - (void)fd_reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [sections enumerateIndexesUsingBlock: ^(NSUInteger section, BOOL *stop) { [self.fd_indexPathHeightCache buildSectionsIfNeeded:section]; [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection[section] removeAllObjects]; }]; }]; } FDPrimaryCall([self fd_reloadSections:sections withRowAnimation:animation];); } - (void)fd_moveSection:(NSInteger)section toSection:(NSInteger)newSection { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [self.fd_indexPathHeightCache buildSectionsIfNeeded:section]; [self.fd_indexPathHeightCache buildSectionsIfNeeded:newSection]; [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection exchangeObjectAtIndex:section withObjectAtIndex:newSection]; }]; } FDPrimaryCall([self fd_moveSection:section toSection:newSection];); } - (void)fd_insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [self.fd_indexPathHeightCache buildCachesAtIndexPathsIfNeeded:indexPaths]; [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) { [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection[indexPath.section] insertObject:@-1 atIndex:indexPath.row]; }]; }]; } FDPrimaryCall([self fd_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];); } - (void)fd_deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [self.fd_indexPathHeightCache buildCachesAtIndexPathsIfNeeded:indexPaths]; NSMutableDictionary *mutableIndexSetsToRemove = [NSMutableDictionary dictionary]; [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) { NSMutableIndexSet *mutableIndexSet = mutableIndexSetsToRemove[@(indexPath.section)]; if (!mutableIndexSet) { mutableIndexSet = [NSMutableIndexSet indexSet]; mutableIndexSetsToRemove[@(indexPath.section)] = mutableIndexSet; } [mutableIndexSet addIndex:indexPath.row]; }]; [mutableIndexSetsToRemove enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSIndexSet *indexSet, BOOL *stop) { [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { [heightsBySection[key.integerValue] removeObjectsAtIndexes:indexSet]; }]; }]; } FDPrimaryCall([self fd_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];); } - (void)fd_reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [self.fd_indexPathHeightCache buildCachesAtIndexPathsIfNeeded:indexPaths]; [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) { [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { heightsBySection[indexPath.section][indexPath.row] = @-1; }]; }]; } FDPrimaryCall([self fd_reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];); } - (void)fd_moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { if (self.fd_indexPathHeightCache.automaticallyInvalidateEnabled) { [self.fd_indexPathHeightCache buildCachesAtIndexPathsIfNeeded:@[sourceIndexPath, destinationIndexPath]]; [self.fd_indexPathHeightCache enumerateAllOrientationsUsingBlock:^(FDIndexPathHeightsBySection *heightsBySection) { NSMutableArray *sourceRows = heightsBySection[sourceIndexPath.section]; NSMutableArray *destinationRows = heightsBySection[destinationIndexPath.section]; NSNumber *sourceValue = sourceRows[sourceIndexPath.row]; NSNumber *destinationValue = destinationRows[destinationIndexPath.row]; sourceRows[sourceIndexPath.row] = destinationValue; destinationRows[destinationIndexPath.row] = sourceValue; }]; } FDPrimaryCall([self fd_moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];); } @end ================================================ FILE: Classes/UITableView+FDKeyedHeightCache.h ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import @interface FDKeyedHeightCache : NSObject - (BOOL)existsHeightForKey:(id)key; - (void)cacheHeight:(CGFloat)height byKey:(id)key; - (CGFloat)heightForKey:(id)key; // Invalidation - (void)invalidateHeightForKey:(id)key; - (void)invalidateAllHeightCache; @end @interface UITableView (FDKeyedHeightCache) /// Height cache by key. Generally, you don't need to use it directly. @property (nonatomic, strong, readonly) FDKeyedHeightCache *fd_keyedHeightCache; @end ================================================ FILE: Classes/UITableView+FDKeyedHeightCache.m ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import "UITableView+FDKeyedHeightCache.h" #import @interface FDKeyedHeightCache () @property (nonatomic, strong) NSMutableDictionary, NSNumber *> *mutableHeightsByKeyForPortrait; @property (nonatomic, strong) NSMutableDictionary, NSNumber *> *mutableHeightsByKeyForLandscape; @end @implementation FDKeyedHeightCache - (instancetype)init { self = [super init]; if (self) { _mutableHeightsByKeyForPortrait = [NSMutableDictionary dictionary]; _mutableHeightsByKeyForLandscape = [NSMutableDictionary dictionary]; } return self; } - (NSMutableDictionary, NSNumber *> *)mutableHeightsByKeyForCurrentOrientation { return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) ? self.mutableHeightsByKeyForPortrait: self.mutableHeightsByKeyForLandscape; } - (BOOL)existsHeightForKey:(id)key { NSNumber *number = self.mutableHeightsByKeyForCurrentOrientation[key]; return number && ![number isEqualToNumber:@-1]; } - (void)cacheHeight:(CGFloat)height byKey:(id)key { self.mutableHeightsByKeyForCurrentOrientation[key] = @(height); } - (CGFloat)heightForKey:(id)key { #if CGFLOAT_IS_DOUBLE return [self.mutableHeightsByKeyForCurrentOrientation[key] doubleValue]; #else return [self.mutableHeightsByKeyForCurrentOrientation[key] floatValue]; #endif } - (void)invalidateHeightForKey:(id)key { [self.mutableHeightsByKeyForPortrait removeObjectForKey:key]; [self.mutableHeightsByKeyForLandscape removeObjectForKey:key]; } - (void)invalidateAllHeightCache { [self.mutableHeightsByKeyForPortrait removeAllObjects]; [self.mutableHeightsByKeyForLandscape removeAllObjects]; } @end @implementation UITableView (FDKeyedHeightCache) - (FDKeyedHeightCache *)fd_keyedHeightCache { FDKeyedHeightCache *cache = objc_getAssociatedObject(self, _cmd); if (!cache) { cache = [FDKeyedHeightCache new]; objc_setAssociatedObject(self, _cmd, cache, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return cache; } @end ================================================ FILE: Classes/UITableView+FDTemplateLayoutCell.h ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import #import "UITableView+FDKeyedHeightCache.h" #import "UITableView+FDIndexPathHeightCache.h" #import "UITableView+FDTemplateLayoutCellDebug.h" @interface UITableView (FDTemplateLayoutCell) /// Access to internal template layout cell for given reuse identifier. /// Generally, you don't need to know these template layout cells. /// /// @param identifier Reuse identifier for cell which must be registered. /// - (__kindof UITableViewCell *)fd_templateCellForReuseIdentifier:(NSString *)identifier; /// Returns height of cell of type specifed by a reuse identifier and configured /// by the configuration block. /// /// The cell would be layed out on a fixed-width, vertically expanding basis with /// respect to its dynamic content, using auto layout. Thus, it is imperative that /// the cell was set up to be self-satisfied, i.e. its content always determines /// its height given the width is equal to the tableview's. /// /// @param identifier A string identifier for retrieving and maintaining template /// cells with system's "-dequeueReusableCellWithIdentifier:" call. /// @param configuration An optional block for configuring and providing content /// to the template cell. The configuration should be minimal for scrolling /// performance yet sufficient for calculating cell's height. /// - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:(void (^)(id cell))configuration; /// This method does what "-fd_heightForCellWithIdentifier:configuration" does, and /// calculated height will be cached by its index path, returns a cached height /// when needed. Therefore lots of extra height calculations could be saved. /// /// No need to worry about invalidating cached heights when data source changes, it /// will be done automatically when you call "-reloadData" or any method that triggers /// UITableView's reloading. /// /// @param indexPath where this cell's height cache belongs. /// - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(void (^)(id cell))configuration; /// This method caches height by your model entity's identifier. /// If your model's changed, call "-invalidateHeightForKey:(id )key" to /// invalidate cache and re-calculate, it's much cheaper and effective than "cacheByIndexPath". /// /// @param key model entity's identifier whose data configures a cell. /// - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByKey:(id)key configuration:(void (^)(id cell))configuration; @end @interface UITableView (FDTemplateLayoutHeaderFooterView) /// Returns header or footer view's height that registered in table view with reuse identifier. /// /// Use it after calling "-[UITableView registerNib/Class:forHeaderFooterViewReuseIdentifier]", /// same with "-fd_heightForCellWithIdentifier:configuration:", it will call "-sizeThatFits:" for /// subclass of UITableViewHeaderFooterView which is not using Auto Layout. /// - (CGFloat)fd_heightForHeaderFooterViewWithIdentifier:(NSString *)identifier configuration:(void (^)(id headerFooterView))configuration; @end @interface UITableViewCell (FDTemplateLayoutCell) /// Indicate this is a template layout cell for calculation only. /// You may need this when there are non-UI side effects when configure a cell. /// Like: /// - (void)configureCell:(FooCell *)cell atIndexPath:(NSIndexPath *)indexPath { /// cell.entity = [self entityAtIndexPath:indexPath]; /// if (!cell.fd_isTemplateLayoutCell) { /// [self notifySomething]; // non-UI side effects /// } /// } /// @property (nonatomic, assign) BOOL fd_isTemplateLayoutCell; /// Enable to enforce this template layout cell to use "frame layout" rather than "auto layout", /// and will ask cell's height by calling "-sizeThatFits:", so you must override this method. /// Use this property only when you want to manually control this template layout cell's height /// calculation mode, default to NO. /// @property (nonatomic, assign) BOOL fd_enforceFrameLayout; @end ================================================ FILE: Classes/UITableView+FDTemplateLayoutCell.m ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import "UITableView+FDTemplateLayoutCell.h" #import @implementation UITableView (FDTemplateLayoutCell) - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell { CGFloat contentViewWidth = CGRectGetWidth(self.frame); CGRect cellBounds = cell.bounds; cellBounds.size.width = contentViewWidth; cell.bounds = cellBounds; CGFloat rightSystemViewsWidth = 0.0; for (UIView *view in self.subviews) { if ([view isKindOfClass:NSClassFromString(@"UITableViewIndex")]) { rightSystemViewsWidth = CGRectGetWidth(view.frame); break; } } // If a cell has accessory view or system accessory type, its content view's width is smaller // than cell's by some fixed values. if (cell.accessoryView) { rightSystemViewsWidth += 16 + CGRectGetWidth(cell.accessoryView.frame); } else { static const CGFloat systemAccessoryWidths[] = { [UITableViewCellAccessoryNone] = 0, [UITableViewCellAccessoryDisclosureIndicator] = 34, [UITableViewCellAccessoryDetailDisclosureButton] = 68, [UITableViewCellAccessoryCheckmark] = 40, [UITableViewCellAccessoryDetailButton] = 48 }; rightSystemViewsWidth += systemAccessoryWidths[cell.accessoryType]; } if ([UIScreen mainScreen].scale >= 3 && [UIScreen mainScreen].bounds.size.width >= 414) { rightSystemViewsWidth += 4; } contentViewWidth -= rightSystemViewsWidth; // If not using auto layout, you have to override "-sizeThatFits:" to provide a fitting size by yourself. // This is the same height calculation passes used in iOS8 self-sizing cell's implementation. // // 1. Try "- systemLayoutSizeFittingSize:" first. (skip this step if 'fd_enforceFrameLayout' set to YES.) // 2. Warning once if step 1 still returns 0 when using AutoLayout // 3. Try "- sizeThatFits:" if step 1 returns 0 // 4. Use a valid height or default row height (44) if not exist one CGFloat fittingHeight = 0; if (!cell.fd_enforceFrameLayout && contentViewWidth > 0) { // Add a hard width constraint to make dynamic content views (like labels) expand vertically instead // of growing horizontally, in a flow-layout manner. NSLayoutConstraint *widthFenceConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:contentViewWidth]; // [bug fix] after iOS 10.3, Auto Layout engine will add an additional 0 width constraint onto cell's content view, to avoid that, we add constraints to content view's left, right, top and bottom. static BOOL isSystemVersionEqualOrGreaterThen10_2 = NO; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ isSystemVersionEqualOrGreaterThen10_2 = [UIDevice.currentDevice.systemVersion compare:@"10.2" options:NSNumericSearch] != NSOrderedAscending; }); NSArray *edgeConstraints; if (isSystemVersionEqualOrGreaterThen10_2) { // To avoid confilicts, make width constraint softer than required (1000) widthFenceConstraint.priority = UILayoutPriorityRequired - 1; // Build edge constraints NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeRight multiplier:1.0 constant:-rightSystemViewsWidth]; NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]; NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]; edgeConstraints = @[leftConstraint, rightConstraint, topConstraint, bottomConstraint]; [cell addConstraints:edgeConstraints]; } [cell.contentView addConstraint:widthFenceConstraint]; // Auto layout engine does its math fittingHeight = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; // Clean-ups [cell.contentView removeConstraint:widthFenceConstraint]; if (isSystemVersionEqualOrGreaterThen10_2) { [cell removeConstraints:edgeConstraints]; } [self fd_debugLog:[NSString stringWithFormat:@"calculate using system fitting size (AutoLayout) - %@", @(fittingHeight)]]; } if (fittingHeight == 0) { #if DEBUG // Warn if using AutoLayout but get zero height. if (cell.contentView.constraints.count > 0) { if (!objc_getAssociatedObject(self, _cmd)) { NSLog(@"[FDTemplateLayoutCell] Warning once only: Cannot get a proper cell height (now 0) from '- systemFittingSize:'(AutoLayout). You should check how constraints are built in cell, making it into 'self-sizing' cell."); objc_setAssociatedObject(self, _cmd, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } } #endif // Try '- sizeThatFits:' for frame layout. // Note: fitting height should not include separator view. fittingHeight = [cell sizeThatFits:CGSizeMake(contentViewWidth, 0)].height; [self fd_debugLog:[NSString stringWithFormat:@"calculate using sizeThatFits - %@", @(fittingHeight)]]; } // Still zero height after all above. if (fittingHeight == 0) { // Use default row height. fittingHeight = 44; } // Add 1px extra space for separator line if needed, simulating default UITableViewCell. if (self.separatorStyle != UITableViewCellSeparatorStyleNone) { fittingHeight += 1.0 / [UIScreen mainScreen].scale; } return fittingHeight; } - (__kindof UITableViewCell *)fd_templateCellForReuseIdentifier:(NSString *)identifier { NSAssert(identifier.length > 0, @"Expect a valid identifier - %@", identifier); NSMutableDictionary *templateCellsByIdentifiers = objc_getAssociatedObject(self, _cmd); if (!templateCellsByIdentifiers) { templateCellsByIdentifiers = @{}.mutableCopy; objc_setAssociatedObject(self, _cmd, templateCellsByIdentifiers, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } UITableViewCell *templateCell = templateCellsByIdentifiers[identifier]; if (!templateCell) { templateCell = [self dequeueReusableCellWithIdentifier:identifier]; NSAssert(templateCell != nil, @"Cell must be registered to table view for identifier - %@", identifier); templateCell.fd_isTemplateLayoutCell = YES; templateCell.contentView.translatesAutoresizingMaskIntoConstraints = NO; templateCellsByIdentifiers[identifier] = templateCell; [self fd_debugLog:[NSString stringWithFormat:@"layout cell created - %@", identifier]]; } return templateCell; } - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:(void (^)(id cell))configuration { if (!identifier) { return 0; } UITableViewCell *templateLayoutCell = [self fd_templateCellForReuseIdentifier:identifier]; // Manually calls to ensure consistent behavior with actual cells. (that are displayed on screen) [templateLayoutCell prepareForReuse]; // Customize and provide content for our template cell. if (configuration) { configuration(templateLayoutCell); } return [self fd_systemFittingHeightForConfiguratedCell:templateLayoutCell]; } - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(void (^)(id cell))configuration { if (!identifier || !indexPath) { return 0; } // Hit cache if ([self.fd_indexPathHeightCache existsHeightAtIndexPath:indexPath]) { [self fd_debugLog:[NSString stringWithFormat:@"hit cache by index path[%@:%@] - %@", @(indexPath.section), @(indexPath.row), @([self.fd_indexPathHeightCache heightForIndexPath:indexPath])]]; return [self.fd_indexPathHeightCache heightForIndexPath:indexPath]; } CGFloat height = [self fd_heightForCellWithIdentifier:identifier configuration:configuration]; [self.fd_indexPathHeightCache cacheHeight:height byIndexPath:indexPath]; [self fd_debugLog:[NSString stringWithFormat: @"cached by index path[%@:%@] - %@", @(indexPath.section), @(indexPath.row), @(height)]]; return height; } - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByKey:(id)key configuration:(void (^)(id cell))configuration { if (!identifier || !key) { return 0; } // Hit cache if ([self.fd_keyedHeightCache existsHeightForKey:key]) { CGFloat cachedHeight = [self.fd_keyedHeightCache heightForKey:key]; [self fd_debugLog:[NSString stringWithFormat:@"hit cache by key[%@] - %@", key, @(cachedHeight)]]; return cachedHeight; } CGFloat height = [self fd_heightForCellWithIdentifier:identifier configuration:configuration]; [self.fd_keyedHeightCache cacheHeight:height byKey:key]; [self fd_debugLog:[NSString stringWithFormat:@"cached by key[%@] - %@", key, @(height)]]; return height; } @end @implementation UITableView (FDTemplateLayoutHeaderFooterView) - (__kindof UITableViewHeaderFooterView *)fd_templateHeaderFooterViewForReuseIdentifier:(NSString *)identifier { NSAssert(identifier.length > 0, @"Expect a valid identifier - %@", identifier); NSMutableDictionary *templateHeaderFooterViews = objc_getAssociatedObject(self, _cmd); if (!templateHeaderFooterViews) { templateHeaderFooterViews = @{}.mutableCopy; objc_setAssociatedObject(self, _cmd, templateHeaderFooterViews, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } UITableViewHeaderFooterView *templateHeaderFooterView = templateHeaderFooterViews[identifier]; if (!templateHeaderFooterView) { templateHeaderFooterView = [self dequeueReusableHeaderFooterViewWithIdentifier:identifier]; NSAssert(templateHeaderFooterView != nil, @"HeaderFooterView must be registered to table view for identifier - %@", identifier); templateHeaderFooterView.contentView.translatesAutoresizingMaskIntoConstraints = NO; templateHeaderFooterViews[identifier] = templateHeaderFooterView; [self fd_debugLog:[NSString stringWithFormat:@"layout header footer view created - %@", identifier]]; } return templateHeaderFooterView; } - (CGFloat)fd_heightForHeaderFooterViewWithIdentifier:(NSString *)identifier configuration:(void (^)(id))configuration { UITableViewHeaderFooterView *templateHeaderFooterView = [self fd_templateHeaderFooterViewForReuseIdentifier:identifier]; NSLayoutConstraint *widthFenceConstraint = [NSLayoutConstraint constraintWithItem:templateHeaderFooterView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:CGRectGetWidth(self.frame)]; [templateHeaderFooterView addConstraint:widthFenceConstraint]; CGFloat fittingHeight = [templateHeaderFooterView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; [templateHeaderFooterView removeConstraint:widthFenceConstraint]; if (fittingHeight == 0) { fittingHeight = [templateHeaderFooterView sizeThatFits:CGSizeMake(CGRectGetWidth(self.frame), 0)].height; } return fittingHeight; } @end @implementation UITableViewCell (FDTemplateLayoutCell) - (BOOL)fd_isTemplateLayoutCell { return [objc_getAssociatedObject(self, _cmd) boolValue]; } - (void)setFd_isTemplateLayoutCell:(BOOL)isTemplateLayoutCell { objc_setAssociatedObject(self, @selector(fd_isTemplateLayoutCell), @(isTemplateLayoutCell), OBJC_ASSOCIATION_RETAIN); } - (BOOL)fd_enforceFrameLayout { return [objc_getAssociatedObject(self, _cmd) boolValue]; } - (void)setFd_enforceFrameLayout:(BOOL)enforceFrameLayout { objc_setAssociatedObject(self, @selector(fd_enforceFrameLayout), @(enforceFrameLayout), OBJC_ASSOCIATION_RETAIN); } @end ================================================ FILE: Classes/UITableView+FDTemplateLayoutCellDebug.h ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import @interface UITableView (FDTemplateLayoutCellDebug) /// Helps to debug or inspect what is this "FDTemplateLayoutCell" extention doing, /// turning on to print logs when "creating", "calculating", "precaching" or "hitting cache". /// /// Default to NO, log by NSLog. /// @property (nonatomic, assign) BOOL fd_debugLogEnabled; /// Debug log controlled by "fd_debugLogEnabled". - (void)fd_debugLog:(NSString *)message; @end ================================================ FILE: Classes/UITableView+FDTemplateLayoutCellDebug.m ================================================ // The MIT License (MIT) // // Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #import "UITableView+FDTemplateLayoutCellDebug.h" #import @implementation UITableView (FDTemplateLayoutCellDebug) - (BOOL)fd_debugLogEnabled { return [objc_getAssociatedObject(self, _cmd) boolValue]; } - (void)setFd_debugLogEnabled:(BOOL)debugLogEnabled { objc_setAssociatedObject(self, @selector(fd_debugLogEnabled), @(debugLogEnabled), OBJC_ASSOCIATION_RETAIN); } - (void)fd_debugLog:(NSString *)message { if (self.fd_debugLogEnabled) { NSLog(@"** FDTemplateLayoutCell ** %@", message); } } @end ================================================ FILE: Demo/Demo/Base.lproj/LaunchScreen.xib ================================================ ================================================ FILE: Demo/Demo/Base.lproj/Main.storyboard ================================================ ================================================ FILE: Demo/Demo/FDAppDelegate.h ================================================ // // AppDelegate.h // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import @interface FDAppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end ================================================ FILE: Demo/Demo/FDAppDelegate.m ================================================ // // AppDelegate.m // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import "FDAppDelegate.h" @implementation FDAppDelegate @end ================================================ FILE: Demo/Demo/FDFeedCell.h ================================================ // // FDFeedCell.h // Demo // // Created by sunnyxx on 15/4/17. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import #import "FDFeedEntity.h" @interface FDFeedCell : UITableViewCell @property (nonatomic, strong) FDFeedEntity *entity; @end ================================================ FILE: Demo/Demo/FDFeedCell.m ================================================ // // FDFeedCell.m // Demo // // Created by sunnyxx on 15/4/17. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import "FDFeedCell.h" @interface FDFeedCell () @property (nonatomic, weak) IBOutlet UILabel *titleLabel; @property (nonatomic, weak) IBOutlet UILabel *contentLabel; @property (nonatomic, weak) IBOutlet UIImageView *contentImageView; @property (nonatomic, weak) IBOutlet UILabel *usernameLabel; @property (nonatomic, weak) IBOutlet UILabel *timeLabel; @end @implementation FDFeedCell - (void)awakeFromNib { [super awakeFromNib]; // Fix the bug in iOS7 - initial constraints warning self.contentView.bounds = [UIScreen mainScreen].bounds; } - (void)setEntity:(FDFeedEntity *)entity { _entity = entity; self.titleLabel.text = entity.title; self.contentLabel.text = entity.content; self.contentImageView.image = entity.imageName.length > 0 ? [UIImage imageNamed:entity.imageName] : nil; self.usernameLabel.text = entity.username; self.timeLabel.text = entity.time; } // If you are not using auto layout, override this method, enable it by setting // "fd_enforceFrameLayout" to YES. - (CGSize)sizeThatFits:(CGSize)size { CGFloat totalHeight = 0; totalHeight += [self.titleLabel sizeThatFits:size].height; totalHeight += [self.contentLabel sizeThatFits:size].height; totalHeight += [self.contentImageView sizeThatFits:size].height; totalHeight += [self.usernameLabel sizeThatFits:size].height; totalHeight += 40; // margins return CGSizeMake(size.width, totalHeight); } @end ================================================ FILE: Demo/Demo/FDFeedEntity.h ================================================ // // FDFeedEntity.h // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import @interface FDFeedEntity : NSObject - (instancetype)initWithDictionary:(NSDictionary *)dictionary; @property (nonatomic, copy, readonly) NSString *identifier; @property (nonatomic, copy, readonly) NSString *title; @property (nonatomic, copy, readonly) NSString *content; @property (nonatomic, copy, readonly) NSString *username; @property (nonatomic, copy, readonly) NSString *time; @property (nonatomic, copy, readonly) NSString *imageName; @end ================================================ FILE: Demo/Demo/FDFeedEntity.m ================================================ // // FDFeedEntity.m // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import "FDFeedEntity.h" @implementation FDFeedEntity - (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = super.init; if (self) { _identifier = [self uniqueIdentifier]; _title = dictionary[@"title"]; _content = dictionary[@"content"]; _username = dictionary[@"username"]; _time = dictionary[@"time"]; _imageName = dictionary[@"imageName"]; } return self; } - (NSString *)uniqueIdentifier { static NSInteger counter = 0; return [NSString stringWithFormat:@"unique-id-%@", @(counter++)]; } @end ================================================ FILE: Demo/Demo/FDFeedViewController.h ================================================ // // FDFeedViewController.h // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import @interface FDFeedViewController : UITableViewController @end ================================================ FILE: Demo/Demo/FDFeedViewController.m ================================================ // // FDFeedViewController.m // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import "FDFeedViewController.h" #import "UITableView+FDTemplateLayoutCell.h" #import "FDFeedEntity.h" #import "FDFeedCell.h" typedef NS_ENUM(NSInteger, FDSimulatedCacheMode) { FDSimulatedCacheModeNone = 0, FDSimulatedCacheModeCacheByIndexPath, FDSimulatedCacheModeCacheByKey }; @interface FDFeedViewController () @property (nonatomic, copy) NSArray *prototypeEntitiesFromJSON; @property (nonatomic, strong) NSMutableArray *feedEntitySections; // 2d array @property (nonatomic, weak) IBOutlet UISegmentedControl *cacheModeSegmentControl; @end @implementation FDFeedViewController - (void)viewDidLoad { [super viewDidLoad]; self.tableView.fd_debugLogEnabled = YES; // Cache by index path initial self.cacheModeSegmentControl.selectedSegmentIndex = 1; [self buildTestDataThen:^{ self.feedEntitySections = @[].mutableCopy; [self.feedEntitySections addObject:self.prototypeEntitiesFromJSON.mutableCopy]; [self.tableView reloadData]; }]; } - (void)buildTestDataThen:(void (^)(void))then { // Simulate an async request dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // Data from `data.json` NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"]; NSData *data = [NSData dataWithContentsOfFile:dataFilePath]; NSDictionary *rootDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; NSArray *feedDicts = rootDict[@"feed"]; // Convert to `FDFeedEntity` NSMutableArray *entities = @[].mutableCopy; [feedDicts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [entities addObject:[[FDFeedEntity alloc] initWithDictionary:obj]]; }]; self.prototypeEntitiesFromJSON = entities; // Callback dispatch_async(dispatch_get_main_queue(), ^{ !then ?: then(); }); }); } #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.feedEntitySections.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.feedEntitySections[section] count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { FDFeedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FDFeedCell"]; [self configureCell:cell atIndexPath:indexPath]; return cell; } - (void)configureCell:(FDFeedCell *)cell atIndexPath:(NSIndexPath *)indexPath { cell.fd_enforceFrameLayout = NO; // Enable to use "-sizeThatFits:" if (indexPath.row % 2 == 0) { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } else { cell.accessoryType = UITableViewCellAccessoryCheckmark; } cell.entity = self.feedEntitySections[indexPath.section][indexPath.row]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return @[@"A",@"B",@"C",@"D"]; } #pragma mark - UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { FDSimulatedCacheMode mode = self.cacheModeSegmentControl.selectedSegmentIndex; switch (mode) { case FDSimulatedCacheModeNone: return [tableView fd_heightForCellWithIdentifier:@"FDFeedCell" configuration:^(FDFeedCell *cell) { [self configureCell:cell atIndexPath:indexPath]; }]; case FDSimulatedCacheModeCacheByIndexPath: return [tableView fd_heightForCellWithIdentifier:@"FDFeedCell" cacheByIndexPath:indexPath configuration:^(FDFeedCell *cell) { [self configureCell:cell atIndexPath:indexPath]; }]; case FDSimulatedCacheModeCacheByKey: { FDFeedEntity *entity = self.feedEntitySections[indexPath.section][indexPath.row]; return [tableView fd_heightForCellWithIdentifier:@"FDFeedCell" cacheByKey:entity.identifier configuration:^(FDFeedCell *cell) { [self configureCell:cell atIndexPath:indexPath]; }]; }; default: break; } } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSMutableArray *mutableEntities = self.feedEntitySections[indexPath.section]; [mutableEntities removeObjectAtIndex:indexPath.row]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } } #pragma mark - Actions - (IBAction)refreshControlAction:(UIRefreshControl *)sender { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.feedEntitySections removeAllObjects]; [self.feedEntitySections addObject:self.prototypeEntitiesFromJSON.mutableCopy]; [self.tableView reloadData]; [sender endRefreshing]; }); } - (IBAction)rightNavigationItemAction:(id)sender { [[[UIActionSheet alloc] initWithTitle:@"Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Insert a row", @"Insert a section", @"Delete a section", nil] showInView:self.view]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { SEL selectors[] = { @selector(insertRow), @selector(insertSection), @selector(deleteSection) }; if (buttonIndex < sizeof(selectors) / sizeof(SEL)) { void(*imp)(id, SEL) = (typeof(imp))[self methodForSelector:selectors[buttonIndex]]; imp(self, selectors[buttonIndex]); } } - (FDFeedEntity *)randomEntity { NSUInteger randomNumber = arc4random_uniform((int32_t)self.prototypeEntitiesFromJSON.count); FDFeedEntity *randomEntity = self.prototypeEntitiesFromJSON[randomNumber]; return randomEntity; } - (void)insertRow { if (self.feedEntitySections.count == 0) { [self insertSection]; } else { [self.feedEntitySections[0] insertObject:self.randomEntity atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } } - (void)insertSection { [self.feedEntitySections insertObject:@[self.randomEntity].mutableCopy atIndex:0]; [self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; } - (void)deleteSection { if (self.feedEntitySections.count > 0) { [self.feedEntitySections removeObjectAtIndex:0]; [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; } } @end ================================================ FILE: Demo/Demo/Images.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "3x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "3x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/breaddoge.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "dogebread.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/doge.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "doge@2x.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/forkingdog.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "forkingdog@2x.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/phil.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "phil.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/sark.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "sark@2x.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/sinojerk.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "彪哥副本.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Images.xcassets/sunnyxx.imageset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "下载.png" }, { "idiom" : "universal", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Demo/Demo/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier com.forkingdog.templatelayoutcell.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight ================================================ FILE: Demo/Demo/data.json ================================================ { "feed": [ { "title": "Hello world", "content": "This is forkingdog team. Here's our logo?\nGithub: \"forkingdog\"", "username": "forkingdog", "time": "2015.04.10", "imageName": "forkingdog" }, { "title": "Team member - sunnyxx", "content": "Working at Baidu, Zhidao iOS team, weibo: @我就叫Sunny怎么了", "username": "sunnyxx", "time": "2015.04.11", "imageName": "sunnyxx" }, { "title": "Team member - SinoJerk", "content": "Zhidao iOS team, Daifu Tang (aka 彪哥)", "username": "sinojerk", "time": "2015.04.15", "imageName": "sinojerk" }, { "title": "Team member - Phil", "content": "Zhidao iOS team, Jiaqi Guo, Github: philcn", "username": "phil", "time": "2015.04.15", "imageName": "phil" }, { "title": "William Shakespeare", "content": "Good name in man and woman, dear my lord, is the immediate jewel of their souls: Who steals my purse steals trash; ’tis something, nothing. (Othello 3.3) ", "username": "sunnyxx", "time": "2015.04.12", "imageName": "breaddoge" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "Good name in man and woman, dear my lord, is the immediate jewel of their souls: Who steals my purse steals trash; ’tis something, nothing. (Othello 3.3) ", "username": "sunnyxx", "time": "2015.04.12", "imageName": "breaddoge" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "Hello world", "content": "This is forkingdog team. Here's our logo?\nGithub: \"forkingdog\"", "username": "forkingdog", "time": "2015.04.10", "imageName": "forkingdog" }, { "title": "Team member - sunnyxx", "content": "Working at Baidu, Zhidao iOS team, weibo: @我就叫Sunny怎么了", "username": "sunnyxx", "time": "2015.04.11", "imageName": "sunnyxx" }, { "title": "Team member - SinoJerk", "content": "Zhidao iOS team, Daifu Tang (aka 彪哥)", "username": "sinojerk", "time": "2015.04.15", "imageName": "sinojerk" }, { "title": "Team member - Phil", "content": "Zhidao iOS team, Jiaqi Guo, Github: philcn", "username": "phil", "time": "2015.04.15", "imageName": "phil" }, { "title": "William Shakespeare", "content": "Good name in man and woman, dear my lord, is the immediate jewel of their souls: Who steals my purse steals trash; ’tis something, nothing. (Othello 3.3) ", "username": "sunnyxx", "time": "2015.04.12", "imageName": "breaddoge" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "Good name in man and woman, dear my lord, is the immediate jewel of their souls: Who steals my purse steals trash; ’tis something, nothing. (Othello 3.3) ", "username": "sunnyxx", "time": "2015.04.12", "imageName": "breaddoge" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" },{ "title": "Hello world", "content": "This is forkingdog team. Here's our logo?\nGithub: \"forkingdog\"", "username": "forkingdog", "time": "2015.04.10", "imageName": "forkingdog" }, { "title": "Team member - sunnyxx", "content": "Working at Baidu, Zhidao iOS team, weibo: @我就叫Sunny怎么了", "username": "sunnyxx", "time": "2015.04.11", "imageName": "sunnyxx" }, { "title": "Team member - SinoJerk", "content": "Zhidao iOS team, Daifu Tang (aka 彪哥)", "username": "sinojerk", "time": "2015.04.15", "imageName": "sinojerk" }, { "title": "Team member - Phil", "content": "Zhidao iOS team, Jiaqi Guo, Github: philcn", "username": "phil", "time": "2015.04.15", "imageName": "phil" }, { "title": "William Shakespeare", "content": "Good name in man and woman, dear my lord, is the immediate jewel of their souls: Who steals my purse steals trash; ’tis something, nothing. (Othello 3.3) ", "username": "sunnyxx", "time": "2015.04.12", "imageName": "breaddoge" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "Good name in man and woman, dear my lord, is the immediate jewel of their souls: Who steals my purse steals trash; ’tis something, nothing. (Othello 3.3) ", "username": "sunnyxx", "time": "2015.04.12", "imageName": "breaddoge" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" }, { "title": "William Shakespeare", "content": "To be, or not to be —that is the question, Whether'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die —to sleep", "username": "sunnyxx", "time": "2015.04.16", "imageName": "" }, { "title": "Sark's bad guy (gay)", "content": "", "username": "sunnyxx", "time": "2015.04.16", "imageName": "sark" }, { "title": "", "content": "Things base and vile, holding no quantity, love can transpose to from and dignity: love looks not with the eyes, but with mind. (A Midsummer Night’s Dream 1.1)", "username": "sunnyxx", "time": "2015.04.17", "imageName": "" } ] } ================================================ FILE: Demo/Demo/main.m ================================================ // // main.m // Demo // // Created by sunnyxx on 15/4/16. // Copyright (c) 2015年 forkingdog. All rights reserved. // #import #import "FDAppDelegate.h" int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([FDAppDelegate class])); } } ================================================ FILE: Demo/Demo.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 485DB89B1BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 485DB89A1BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.m */; settings = {ASSET_TAGS = (); }; }; 485DB89E1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 485DB89D1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.m */; settings = {ASSET_TAGS = (); }; }; 488EECB71ADFEDC6004EAA71 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 488EECB61ADFEDC6004EAA71 /* main.m */; }; 488EECBA1ADFEDC6004EAA71 /* FDAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 488EECB91ADFEDC6004EAA71 /* FDAppDelegate.m */; }; 488EECC01ADFEDC6004EAA71 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 488EECBE1ADFEDC6004EAA71 /* Main.storyboard */; }; 488EECC21ADFEDC6004EAA71 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 488EECC11ADFEDC6004EAA71 /* Images.xcassets */; }; 488EECC51ADFEDC6004EAA71 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 488EECC31ADFEDC6004EAA71 /* LaunchScreen.xib */; }; 488EECE01ADFF7A5004EAA71 /* FDFeedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 488EECDF1ADFF7A5004EAA71 /* FDFeedViewController.m */; }; 488EECE31ADFF884004EAA71 /* FDFeedEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 488EECE21ADFF884004EAA71 /* FDFeedEntity.m */; }; 48954A261B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 48954A1F1B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.m */; }; 48954A271B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 48954A211B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.m */; }; 4897E5DD1ADFFBBD00E87B5F /* data.json in Resources */ = {isa = PBXBuildFile; fileRef = 4897E5DC1ADFFBBD00E87B5F /* data.json */; }; 4897E5E01AE090B900E87B5F /* FDFeedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4897E5DF1AE090B900E87B5F /* FDFeedCell.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 485DB8991BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDKeyedHeightCache.h"; sourceTree = ""; }; 485DB89A1BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDKeyedHeightCache.m"; sourceTree = ""; }; 485DB89C1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDIndexPathHeightCache.h"; sourceTree = ""; }; 485DB89D1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDIndexPathHeightCache.m"; sourceTree = ""; }; 488EECB11ADFEDC6004EAA71 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 488EECB51ADFEDC6004EAA71 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 488EECB61ADFEDC6004EAA71 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 488EECB81ADFEDC6004EAA71 /* FDAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FDAppDelegate.h; sourceTree = ""; }; 488EECB91ADFEDC6004EAA71 /* FDAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FDAppDelegate.m; sourceTree = ""; }; 488EECBF1ADFEDC6004EAA71 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 488EECC11ADFEDC6004EAA71 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 488EECC41ADFEDC6004EAA71 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 488EECDE1ADFF7A5004EAA71 /* FDFeedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDFeedViewController.h; sourceTree = ""; }; 488EECDF1ADFF7A5004EAA71 /* FDFeedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDFeedViewController.m; sourceTree = ""; }; 488EECE11ADFF884004EAA71 /* FDFeedEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDFeedEntity.h; sourceTree = ""; }; 488EECE21ADFF884004EAA71 /* FDFeedEntity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDFeedEntity.m; sourceTree = ""; }; 48954A1E1B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDTemplateLayoutCell.h"; sourceTree = ""; }; 48954A1F1B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDTemplateLayoutCell.m"; sourceTree = ""; }; 48954A201B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDTemplateLayoutCellDebug.h"; sourceTree = ""; }; 48954A211B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDTemplateLayoutCellDebug.m"; sourceTree = ""; }; 4897E5DC1ADFFBBD00E87B5F /* data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = data.json; sourceTree = ""; }; 4897E5DE1AE090B900E87B5F /* FDFeedCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDFeedCell.h; sourceTree = ""; }; 4897E5DF1AE090B900E87B5F /* FDFeedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDFeedCell.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 488EECAE1ADFEDC6004EAA71 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 488EECA81ADFEDC6004EAA71 = { isa = PBXGroup; children = ( 488EECB31ADFEDC6004EAA71 /* Demo */, 488EECB21ADFEDC6004EAA71 /* Products */, ); sourceTree = ""; }; 488EECB21ADFEDC6004EAA71 /* Products */ = { isa = PBXGroup; children = ( 488EECB11ADFEDC6004EAA71 /* Demo.app */, ); name = Products; sourceTree = ""; }; 488EECB31ADFEDC6004EAA71 /* Demo */ = { isa = PBXGroup; children = ( 48954A191B5102E200EFD15D /* Classes */, 488EECEA1ADFF905004EAA71 /* Feed */, 488EECC11ADFEDC6004EAA71 /* Images.xcassets */, 488EECC31ADFEDC6004EAA71 /* LaunchScreen.xib */, 488EECB41ADFEDC6004EAA71 /* Supporting Files */, ); path = Demo; sourceTree = ""; }; 488EECB41ADFEDC6004EAA71 /* Supporting Files */ = { isa = PBXGroup; children = ( 488EECB51ADFEDC6004EAA71 /* Info.plist */, 488EECB61ADFEDC6004EAA71 /* main.m */, ); name = "Supporting Files"; sourceTree = ""; }; 488EECEA1ADFF905004EAA71 /* Feed */ = { isa = PBXGroup; children = ( 488EECE11ADFF884004EAA71 /* FDFeedEntity.h */, 488EECE21ADFF884004EAA71 /* FDFeedEntity.m */, 488EECB81ADFEDC6004EAA71 /* FDAppDelegate.h */, 488EECB91ADFEDC6004EAA71 /* FDAppDelegate.m */, 488EECDE1ADFF7A5004EAA71 /* FDFeedViewController.h */, 488EECDF1ADFF7A5004EAA71 /* FDFeedViewController.m */, 4897E5DE1AE090B900E87B5F /* FDFeedCell.h */, 4897E5DF1AE090B900E87B5F /* FDFeedCell.m */, 488EECBE1ADFEDC6004EAA71 /* Main.storyboard */, 4897E5DC1ADFFBBD00E87B5F /* data.json */, ); name = Feed; sourceTree = ""; }; 48954A191B5102E200EFD15D /* Classes */ = { isa = PBXGroup; children = ( 48954A1E1B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.h */, 48954A1F1B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.m */, 485DB8991BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.h */, 485DB89A1BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.m */, 485DB89C1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.h */, 485DB89D1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.m */, 48954A201B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.h */, 48954A211B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.m */, ); name = Classes; path = ../../Classes; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 488EECB01ADFEDC6004EAA71 /* Demo */ = { isa = PBXNativeTarget; buildConfigurationList = 488EECD41ADFEDC6004EAA71 /* Build configuration list for PBXNativeTarget "Demo" */; buildPhases = ( 488EECAD1ADFEDC6004EAA71 /* Sources */, 488EECAE1ADFEDC6004EAA71 /* Frameworks */, 488EECAF1ADFEDC6004EAA71 /* Resources */, ); buildRules = ( ); dependencies = ( ); name = Demo; productName = Demo; productReference = 488EECB11ADFEDC6004EAA71 /* Demo.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 488EECA91ADFEDC6004EAA71 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0630; ORGANIZATIONNAME = forkingdog; TargetAttributes = { 488EECB01ADFEDC6004EAA71 = { CreatedOnToolsVersion = 6.3; }; }; }; buildConfigurationList = 488EECAC1ADFEDC6004EAA71 /* Build configuration list for PBXProject "Demo" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = 488EECA81ADFEDC6004EAA71; productRefGroup = 488EECB21ADFEDC6004EAA71 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 488EECB01ADFEDC6004EAA71 /* Demo */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 488EECAF1ADFEDC6004EAA71 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 488EECC01ADFEDC6004EAA71 /* Main.storyboard in Resources */, 488EECC51ADFEDC6004EAA71 /* LaunchScreen.xib in Resources */, 488EECC21ADFEDC6004EAA71 /* Images.xcassets in Resources */, 4897E5DD1ADFFBBD00E87B5F /* data.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 488EECAD1ADFEDC6004EAA71 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 488EECBA1ADFEDC6004EAA71 /* FDAppDelegate.m in Sources */, 48954A261B5102E200EFD15D /* UITableView+FDTemplateLayoutCell.m in Sources */, 48954A271B5102E200EFD15D /* UITableView+FDTemplateLayoutCellDebug.m in Sources */, 488EECE01ADFF7A5004EAA71 /* FDFeedViewController.m in Sources */, 4897E5E01AE090B900E87B5F /* FDFeedCell.m in Sources */, 488EECB71ADFEDC6004EAA71 /* main.m in Sources */, 485DB89B1BAFFF8900CEAE33 /* UITableView+FDKeyedHeightCache.m in Sources */, 485DB89E1BB0004300CEAE33 /* UITableView+FDIndexPathHeightCache.m in Sources */, 488EECE31ADFF884004EAA71 /* FDFeedEntity.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ 488EECBE1ADFEDC6004EAA71 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( 488EECBF1ADFEDC6004EAA71 /* Base */, ); name = Main.storyboard; sourceTree = ""; }; 488EECC31ADFEDC6004EAA71 /* LaunchScreen.xib */ = { isa = PBXVariantGroup; children = ( 488EECC41ADFEDC6004EAA71 /* Base */, ); name = LaunchScreen.xib; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ 488EECD21ADFEDC6004EAA71 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 6.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; }; 488EECD31ADFEDC6004EAA71 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 6.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; }; 488EECD51ADFEDC6004EAA71 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Demo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; }; 488EECD61ADFEDC6004EAA71 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Demo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 488EECAC1ADFEDC6004EAA71 /* Build configuration list for PBXProject "Demo" */ = { isa = XCConfigurationList; buildConfigurations = ( 488EECD21ADFEDC6004EAA71 /* Debug */, 488EECD31ADFEDC6004EAA71 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 488EECD41ADFEDC6004EAA71 /* Build configuration list for PBXNativeTarget "Demo" */ = { isa = XCConfigurationList; buildConfigurations = ( 488EECD51ADFEDC6004EAA71 /* Debug */, 488EECD61ADFEDC6004EAA71 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 488EECA91ADFEDC6004EAA71 /* Project object */; } ================================================ FILE: Demo/Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: FDTemplateCell.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: FDTemplateCell.xcworkspace/xcshareddata/FDTemplateCell.xcscmblueprint ================================================ { "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "45232C3CDBDF9DB333979E103A0429BCEB54D2EF", "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { }, "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { "32d7d9b4-ffb1-4469-8922-27dbf3d99605++9332" : 0, "45232C3CDBDF9DB333979E103A0429BCEB54D2EF" : 0 }, "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "6569ED7F-B9F6-4B04-BF61-CB6FDE03BD78", "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { "32d7d9b4-ffb1-4469-8922-27dbf3d99605++9332" : "svn\/iknow", "45232C3CDBDF9DB333979E103A0429BCEB54D2EF" : "UITableView-FDTemplateLayoutCell" }, "DVTSourceControlWorkspaceBlueprintNameKey" : "FDTemplateCell", "DVTSourceControlWorkspaceBlueprintVersion" : 204, "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "FDTemplateCell.xcworkspace", "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ { "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/svn.baidu.com\/app\/search\/iknow", "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Subversion", "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "32d7d9b4-ffb1-4469-8922-27dbf3d99605++9332" }, { "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/forkingdog\/UITableView-FDTemplateLayoutCell.git", "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "45232C3CDBDF9DB333979E103A0429BCEB54D2EF" } ] } ================================================ FILE: FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 485022131C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 4850220D1C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 485022141C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 4850220E1C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.m */; }; 485022151C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 4850220F1C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 485022161C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 485022101C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.m */; }; 485022171C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 485022111C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.h */; settings = {ATTRIBUTES = (Public, ); }; }; 485022181C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 485022121C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.m */; }; E19608D11BAD53AF00BDCBBE /* FDTemplateLayoutCell.h in Headers */ = {isa = PBXBuildFile; fileRef = E19608D01BAD53AF00BDCBBE /* FDTemplateLayoutCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; E19608E01BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.h in Headers */ = {isa = PBXBuildFile; fileRef = E19608DE1BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; E19608E11BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E19608DF1BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 4850220D1C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDIndexPathHeightCache.h"; sourceTree = ""; }; 4850220E1C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDIndexPathHeightCache.m"; sourceTree = ""; }; 4850220F1C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDKeyedHeightCache.h"; sourceTree = ""; }; 485022101C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDKeyedHeightCache.m"; sourceTree = ""; }; 485022111C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDTemplateLayoutCellDebug.h"; sourceTree = ""; }; 485022121C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDTemplateLayoutCellDebug.m"; sourceTree = ""; }; E19608CD1BAD53AF00BDCBBE /* FDTemplateLayoutCell.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FDTemplateLayoutCell.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E19608D01BAD53AF00BDCBBE /* FDTemplateLayoutCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FDTemplateLayoutCell.h; sourceTree = ""; }; E19608D21BAD53AF00BDCBBE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E19608DE1BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+FDTemplateLayoutCell.h"; sourceTree = ""; }; E19608DF1BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+FDTemplateLayoutCell.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ E19608C91BAD53AF00BDCBBE /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ E19608C31BAD53AE00BDCBBE = { isa = PBXGroup; children = ( E19608DD1BAD54EB00BDCBBE /* Classes */, E19608CF1BAD53AF00BDCBBE /* FDTemplateLayoutCell */, E19608CE1BAD53AF00BDCBBE /* Products */, ); sourceTree = ""; }; E19608CE1BAD53AF00BDCBBE /* Products */ = { isa = PBXGroup; children = ( E19608CD1BAD53AF00BDCBBE /* FDTemplateLayoutCell.framework */, ); name = Products; sourceTree = ""; }; E19608CF1BAD53AF00BDCBBE /* FDTemplateLayoutCell */ = { isa = PBXGroup; children = ( E19608D01BAD53AF00BDCBBE /* FDTemplateLayoutCell.h */, E19608D21BAD53AF00BDCBBE /* Info.plist */, ); path = FDTemplateLayoutCell; sourceTree = ""; }; E19608DD1BAD54EB00BDCBBE /* Classes */ = { isa = PBXGroup; children = ( 4850220D1C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.h */, 4850220E1C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.m */, 4850220F1C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.h */, 485022101C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.m */, 485022111C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.h */, 485022121C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.m */, E19608DE1BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.h */, E19608DF1BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.m */, ); name = Classes; path = ../Classes; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ E19608CA1BAD53AF00BDCBBE /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( E19608E01BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.h in Headers */, E19608D11BAD53AF00BDCBBE /* FDTemplateLayoutCell.h in Headers */, 485022171C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.h in Headers */, 485022151C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.h in Headers */, 485022131C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ E19608CC1BAD53AF00BDCBBE /* FDTemplateLayoutCell */ = { isa = PBXNativeTarget; buildConfigurationList = E19608D51BAD53AF00BDCBBE /* Build configuration list for PBXNativeTarget "FDTemplateLayoutCell" */; buildPhases = ( E19608C81BAD53AF00BDCBBE /* Sources */, E19608C91BAD53AF00BDCBBE /* Frameworks */, E19608CA1BAD53AF00BDCBBE /* Headers */, E19608CB1BAD53AF00BDCBBE /* Resources */, ); buildRules = ( ); dependencies = ( ); name = FDTemplateLayoutCell; productName = FDTemplateLayoutCell; productReference = E19608CD1BAD53AF00BDCBBE /* FDTemplateLayoutCell.framework */; productType = "com.apple.product-type.framework"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ E19608C41BAD53AE00BDCBBE /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0700; TargetAttributes = { E19608CC1BAD53AF00BDCBBE = { CreatedOnToolsVersion = 7.0; }; }; }; buildConfigurationList = E19608C71BAD53AE00BDCBBE /* Build configuration list for PBXProject "FDTemplateLayoutCell" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, ); mainGroup = E19608C31BAD53AE00BDCBBE; productRefGroup = E19608CE1BAD53AF00BDCBBE /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( E19608CC1BAD53AF00BDCBBE /* FDTemplateLayoutCell */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ E19608CB1BAD53AF00BDCBBE /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ E19608C81BAD53AF00BDCBBE /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 485022161C3A86EC00BD389E /* UITableView+FDKeyedHeightCache.m in Sources */, 485022181C3A86EC00BD389E /* UITableView+FDTemplateLayoutCellDebug.m in Sources */, E19608E11BAD54EB00BDCBBE /* UITableView+FDTemplateLayoutCell.m in Sources */, 485022141C3A86EC00BD389E /* UITableView+FDIndexPathHeightCache.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ E19608D31BAD53AF00BDCBBE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; name = Debug; }; E19608D41BAD53AF00BDCBBE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; name = Release; }; E19608D61BAD53AF00BDCBBE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = FDTemplateLayoutCell/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.forkingdog.templatelayoutcell.FDTemplateLayoutCell; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; name = Debug; }; E19608D71BAD53AF00BDCBBE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = FDTemplateLayoutCell/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.forkingdog.templatelayoutcell.FDTemplateLayoutCell; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ E19608C71BAD53AE00BDCBBE /* Build configuration list for PBXProject "FDTemplateLayoutCell" */ = { isa = XCConfigurationList; buildConfigurations = ( E19608D31BAD53AF00BDCBBE /* Debug */, E19608D41BAD53AF00BDCBBE /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; E19608D51BAD53AF00BDCBBE /* Build configuration list for PBXNativeTarget "FDTemplateLayoutCell" */ = { isa = XCConfigurationList; buildConfigurations = ( E19608D61BAD53AF00BDCBBE /* Debug */, E19608D71BAD53AF00BDCBBE /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = E19608C41BAD53AE00BDCBBE /* Project object */; } ================================================ FILE: FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/xcshareddata/xcschemes/FDTemplateLayoutCell.xcscheme ================================================ ================================================ FILE: FDTemplateLayoutCell/FDTemplateLayoutcell/FDTemplateLayoutCell.h ================================================ // // FDTemplateLayoutCell.h // FDTemplateLayoutCell // // Created by ospreyren on 9/19/15. // // #import //! Project version number for FDTemplateLayoutCell. FOUNDATION_EXPORT double FDTemplateLayoutCellVersionNumber; //! Project version string for FDTemplateLayoutCell. FOUNDATION_EXPORT const unsigned char FDTemplateLayoutCellVersionString[]; #import ================================================ FILE: FDTemplateLayoutCell/FDTemplateLayoutcell/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType FMWK CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2015 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # UITableView-FDTemplateLayoutCell ## Overview Template auto layout cell for **automatically** UITableViewCell height calculating. ![Demo Overview](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/Sceenshots/screenshot2.gif) ## Basic usage If you have a **self-satisfied** cell, then all you have to do is: ``` objc #import "UITableView+FDTemplateLayoutCell.h" - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [tableView fd_heightForCellWithIdentifier:@"reuse identifer" configuration:^(id cell) { // Configure this cell with data, same as what you've done in "-tableView:cellForRowAtIndexPath:" // Like: // cell.entity = self.feedEntities[indexPath.row]; }]; } ``` ## Height Caching API Since iOS8, `-tableView:heightForRowAtIndexPath:` will be called more times than we expect, we can feel these extra calculations when scrolling. So we provide another API with cache by index path: ``` objc - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [tableView fd_heightForCellWithIdentifier:@"identifer" cacheByIndexPath:indexPath configuration:^(id cell) { // configurations }]; } ``` Or, if your entity has an unique identifier, use cache by key API: ``` objc - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { Entity *entity = self.entities[indexPath.row]; return [tableView fd_heightForCellWithIdentifier:@"identifer" cacheByKey:entity.uid configuration:^(id cell) { // configurations }]; } ``` ## Frame layout mode `FDTemplateLayoutCell` offers 2 modes for asking cell's height. 1. Auto layout mode using "-systemLayoutSizeFittingSize:" 2. Frame layout mode using "-sizeThatFits:" Generally, no need to care about modes, it will **automatically** choose a proper mode by whether you have set auto layout constrants on cell's content view. If you want to enforce frame layout mode, enable this property in your cell's configuration block: ``` objc cell.fd_enforceFrameLayout = YES; ``` And if you're using frame layout mode, you must override `-sizeThatFits:` in your customized cell and return content view's height (separator excluded) ``` - (CGSize)sizeThatFits:(CGSize)size { return CGSizeMake(size.width, A+B+C+D+E+....); } ``` ## Debug log Debug log helps to debug or inspect what is this "FDTemplateLayoutCell" extention doing, turning on to print logs when "calculating", "precaching" or "hitting cache".Default to "NO", log by "NSLog". ``` objc self.tableView.fd_debugLogEnabled = YES; ``` It will print like this: ``` objc ** FDTemplateLayoutCell ** layout cell created - FDFeedCell ** FDTemplateLayoutCell ** calculate - [0:0] 233.5 ** FDTemplateLayoutCell ** calculate - [0:1] 155.5 ** FDTemplateLayoutCell ** calculate - [0:2] 258 ** FDTemplateLayoutCell ** calculate - [0:3] 284 ** FDTemplateLayoutCell ** precached - [0:3] 284 ** FDTemplateLayoutCell ** calculate - [0:4] 278.5 ** FDTemplateLayoutCell ** precached - [0:4] 278.5 ** FDTemplateLayoutCell ** hit cache - [0:3] 284 ** FDTemplateLayoutCell ** hit cache - [0:4] 278.5 ** FDTemplateLayoutCell ** hit cache - [0:5] 156 ** FDTemplateLayoutCell ** hit cache - [0:6] 165 ``` ## About self-satisfied cell a fully **self-satisfied** cell is constrainted by auto layout and each edge("top", "left", "bottom", "right") has at least one layout constraint against it. It's the same concept introduced as "self-sizing cell" in iOS8 using auto layout. A bad one :( - missing right and bottom ![non-self-satisfied](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/Sceenshots/screenshot0.png) A good one :) ![self-satisfied](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/Sceenshots/screenshot1.png) ## Notes A template layout cell is created by `-dequeueReusableCellWithIdentifier:` method, it means that you MUST have registered this cell reuse identifier by one of: - A prototype cell of UITableView in storyboard. - Use `-registerNib:forCellReuseIdentifier:` - Use `-registerClass:forCellReuseIdentifier:` ## 如果你在天朝 可以看这篇中文博客: [http://blog.sunnyxx.com/2015/05/17/cell-height-calculation/](http://blog.sunnyxx.com/2015/05/17/cell-height-calculation/) ## Installation Latest version: **1.6** ``` pod search UITableView+FDTemplateLayoutCell ``` If you cannot search out the latest version, try: ``` pod setup ``` ## Release Notes We recommend to use the latest release in cocoapods. - 1.6 fix bug in iOS 10 - 1.4 Refactor, add "cacheByKey" mode, bug fixed - 1.3 Frame layout mode, handle cell's accessory view/type - 1.2 Precache and auto cache invalidation - 1.1 Height cache - 1.0 Basic automatically height calculation ## License MIT ================================================ FILE: UITableView+FDTemplateLayoutCell.podspec ================================================ Pod::Spec.new do |s| s.name = "UITableView+FDTemplateLayoutCell" s.version = "1.6" s.summary = "Template auto layout cell for automatically UITableViewCell height calculate, cache and precache" s.description = "Template auto layout cell for automatically UITableViewCell height calculate, cache and precache. Requires a `self-satisfied` UITableViewCell, using system's `- systemLayoutSizeFittingSize:`, provides heights caching." s.homepage = "https://github.com/forkingdog/UITableView-FDTemplateLayoutCell" # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.license = { :type => "MIT", :file => "LICENSE" } # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.author = { "forkingdog group" => "https://github.com/forkingdog" } # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.platform = :ios, "6.0" # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.source = { :git => "https://github.com/forkingdog/UITableView-FDTemplateLayoutCell.git", :tag => s.version.to_s } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.source_files = "Classes/*.{h,m}" # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.requires_arc = true end