Skip to content

Commit a618212

Browse files
author
Ernesto Rivera
committed
Configurable reload/insert/remove section/rows animations
1 parent 40375f1 commit a618212

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Source/AMBTableViewController.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
- (void)replaceSectionAtIndex:(NSUInteger)index
7070
withSection:(AMBTableViewSection *)section;
7171

72+
/// @name Configuring Animations
73+
74+
/// Reload section/row animation. By default `UITableViewRowAnimationNone`.
75+
@property (nonatomic) UITableViewRowAnimation reloadAnimation;
76+
77+
/// Insert section/row animation. By default `UITableViewRowAnimationAutomatic`.
78+
@property (nonatomic) UITableViewRowAnimation insertAnimation;
79+
80+
/// Insert section/row animation. By default `UITableViewRowAnimationAutomatic`.
81+
@property (nonatomic) UITableViewRowAnimation removeAnimation;
7282

7383
/// @name Convenience Methods
7484

Source/AMBTableViewController.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ @implementation AMBTableViewController
2727

2828
@dynamic sections;
2929

30+
- (void)awakeFromNib
31+
{
32+
[super awakeFromNib];
33+
34+
self.reloadAnimation = UITableViewRowAnimationNone;
35+
self.insertAnimation = UITableViewRowAnimationAutomatic;
36+
self.removeAnimation = UITableViewRowAnimationAutomatic;
37+
}
38+
3039
- (NSString *)description
3140
{
3241
return [[[[[NSString stringWithFormat:@"<%@: %p; sections: %@>", NSStringFromClass(self.class), self, self.sections]
@@ -74,7 +83,7 @@ - (void)insertSection:(AMBTableViewSection *)section
7483
[section update];
7584

7685
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:index]
77-
withRowAnimation:UITableViewRowAnimationAutomatic];
86+
withRowAnimation:self.insertAnimation];
7887
}
7988

8089
- (void)removeSection:(AMBTableViewSection *)section
@@ -92,7 +101,7 @@ - (void)removeSectionAtIndex:(NSUInteger)index
92101
[_mutableSections removeObjectAtIndex:index];
93102

94103
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:index]
95-
withRowAnimation:UITableViewRowAnimationAutomatic];
104+
withRowAnimation:self.removeAnimation];
96105
}
97106

98107
- (void)replaceSection:(AMBTableViewSection *)sectionToReplace
@@ -542,7 +551,7 @@ - (void)reload
542551
{
543552
NSUInteger sectionIndex = [self.controller.sections indexOfObject:self];
544553
[self.controller.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex]
545-
withRowAnimation:UITableViewRowAnimationNone];
554+
withRowAnimation:self.controller.reloadAnimation];
546555
}
547556
}
548557

@@ -573,7 +582,7 @@ - (void)reloadObjectsAtIndexes:(NSIndexSet *)indexSet
573582
{
574583
NSArray * pathsToReload = [self indexPathsForRowIndexes:[self rowIndexSetForVisibleObjectsInIndexSet:visibleObjectIndexesToReload]];
575584
[self.controller.tableView reloadRowsAtIndexPaths:pathsToReload
576-
withRowAnimation:UITableViewRowAnimationNone];
585+
withRowAnimation:self.controller.reloadAnimation];
577586
}
578587
}
579588
}
@@ -630,7 +639,7 @@ - (void)insertRowsWithIndexes:(NSIndexSet *)rowIndexSet
630639
if (self.controller.tableView)
631640
{
632641
[self.controller.tableView insertRowsAtIndexPaths:[self indexPathsForRowIndexes:rowIndexSet]
633-
withRowAnimation:UITableViewRowAnimationFade];
642+
withRowAnimation:self.controller.insertAnimation];
634643
}
635644
}
636645

@@ -639,7 +648,7 @@ - (void)deleteRowsWithIndexes:(NSIndexSet *)rowIndexSet
639648
if (self.controller.tableView)
640649
{
641650
[self.controller.tableView deleteRowsAtIndexPaths:[self indexPathsForRowIndexes:rowIndexSet]
642-
withRowAnimation:UITableViewRowAnimationFade];
651+
withRowAnimation:self.controller.removeAnimation];
643652
}
644653
}
645654

0 commit comments

Comments
 (0)