1515
1616@interface BOTableViewController ()
1717
18- @property (nonatomic , copy ) NSArray *lastSections;
1918@property (nonatomic ) NSArray *sections;
2019@property (nonatomic ) NSArray *footerViews;
2120
@@ -150,21 +149,47 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
150149 return cell;
151150}
152151
153- - (void )reloadTableView {
152+ - (void )tableView : (UITableView *)tableView willDisplayCell : (BOTableViewCell *)cell forRowAtIndexPath : (NSIndexPath *)indexPath {
153+ [cell _updateAppearance ];
154+ [cell updateAppearance ];
155+ }
156+
157+ - (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
158+ BOTableViewCell *cell = (BOTableViewCell *)[tableView cellForRowAtIndexPath: indexPath];
154159
160+ if ([cell expansionHeight ] > 0 ) {
161+ self.expansionIndexPath = ![indexPath isEqual: self .expansionIndexPath] ? indexPath : nil ;
162+
163+ [self .tableView deselectRowAtIndexPath: indexPath animated: NO ];
164+ [self .tableView beginUpdates ];
165+ [self .tableView endUpdates ];
166+ [self .tableView scrollToRowAtIndexPath: indexPath atScrollPosition: UITableViewScrollPositionMiddle animated: YES ];
167+ } else if (cell.destinationViewController ) {
168+ [self .navigationController pushViewController: cell.destinationViewController animated: YES ];
169+ } else if ([cell respondsToSelector: @selector (wasSelectedFromViewController: )]) {
170+ [cell wasSelectedFromViewController: self ];
171+ }
172+
173+ if (cell.accessoryType != UITableViewCellAccessoryDisclosureIndicator) {
174+ [self .tableView deselectRowAtIndexPath: indexPath animated: YES ];
175+ }
176+ }
177+
155178#pragma mark Dynamic options
179+
180+ - (void )reloadTableView {
156181
157182 NSMutableIndexSet *affectedIndexes = [NSMutableIndexSet new ];
158183
159- for (NSInteger s = 0 ; s < self.tableView . numberOfSections ; s++) {
184+ for (NSInteger s = 0 ; s < self.sections . count ; s++) {
160185 NSInteger numberOfRows = [self .tableView numberOfRowsInSection: s];
161186
162187 if (numberOfRows != [self .sections[s] cells ].count ) {
163188 [affectedIndexes addIndex: s];
164189 } else {
165190 for (NSInteger r = 0 ; r < numberOfRows; r++) {
166191 UITableViewCell *lastCell = [self .tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: r inSection: s]];
167- if (![[self .sections[s] cells ] containsObject: lastCell]) {
192+ if ([ self .tableView.visibleCells containsObject: lastCell] && ![[self .sections[s] cells ] containsObject: lastCell]) {
168193 [affectedIndexes addIndex: s];
169194 }
170195 }
@@ -185,32 +210,6 @@ - (void)reloadTableView {
185210 }];
186211}
187212
188- - (void )tableView : (UITableView *)tableView willDisplayCell : (BOTableViewCell *)cell forRowAtIndexPath : (NSIndexPath *)indexPath {
189- [cell _updateAppearance ];
190- [cell updateAppearance ];
191- }
192-
193- - (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
194- BOTableViewCell *cell = (BOTableViewCell *)[tableView cellForRowAtIndexPath: indexPath];
195-
196- if ([cell expansionHeight ] > 0 ) {
197- self.expansionIndexPath = ![indexPath isEqual: self .expansionIndexPath] ? indexPath : nil ;
198-
199- [self .tableView deselectRowAtIndexPath: indexPath animated: NO ];
200- [self .tableView beginUpdates ];
201- [self .tableView endUpdates ];
202- [self .tableView scrollToRowAtIndexPath: indexPath atScrollPosition: UITableViewScrollPositionMiddle animated: YES ];
203- } else if (cell.destinationViewController ) {
204- [self .navigationController pushViewController: cell.destinationViewController animated: YES ];
205- } else if ([cell respondsToSelector: @selector (wasSelectedFromViewController: )]) {
206- [cell wasSelectedFromViewController: self ];
207- }
208-
209- if (cell.accessoryType != UITableViewCellAccessoryDisclosureIndicator) {
210- [self .tableView deselectRowAtIndexPath: indexPath animated: YES ];
211- }
212- }
213-
214213#pragma mark Dynamic footers
215214
216215- (NSArray *)footerViews {
0 commit comments