This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
BumpTableController.m
541 lines (461 loc) · 22.4 KB
/
BumpTableController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
#import "BumpTableController.h"
#import "BumpTableUtils.h"
#define SEARCH_BAR_HEIGHT 44.0f
/* Class for managing transitions between UITableView updates */
@interface BumpTransition : NSObject
@property (nonatomic,strong) NSSet *inserted;
@property (nonatomic,strong) NSSet *deleted;
@property (nonatomic,strong) NSSet *mutual;
@property (nonatomic,strong) NSSet *moved;
@end
@implementation BumpTransition
- (NSString *)description {
return [NSString stringWithFormat:@"<Transition inserted:%@\ndeleted:%@\nmutual:%@\nmoved:%@\n>",
[BumpTableUtils indentedDescriptionForObject:[_inserted allObjects]],
[BumpTableUtils indentedDescriptionForObject:[_deleted allObjects]],
[BumpTableUtils indentedDescriptionForObject:[_mutual allObjects]],
[BumpTableUtils indentedDescriptionForObject:[_moved allObjects]]];
}
@end
/* Main Controller Class */
@interface BumpTableController () {
UITableView *_tableView;
}
@property (nonatomic) UITableView *searchResultsTableView;
@property (nonatomic) NSString *searchString;
@property (nonatomic) NSArray *searchResultsRows;
@end
@implementation BumpTableController
- (id)initWithTableView:(UITableView *)tableView {
if ((self = [super init])) {
self.tableView = tableView;
self.transitionAnimation = UITableViewRowAnimationTop;
}
return self;
}
- (void)setTableView:(UITableView *)tableView {
_tableView = tableView;
_tableView.dataSource = self;
_tableView.delegate = self;
if (_model) {
[_tableView reloadData];
}
}
- (UITableView *)tableView {
return _tableView;
}
#pragma mark - UITableViewDataSource methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView == _searchResultsTableView) return 1;
return [[_model sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == _searchResultsTableView) {
return [_searchResultsRows count];
}
return [[[self sectionForIndex:section] rows] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BumpTableRow *row = [self rowForTableView:tableView indexPath:indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:row.reuseIdentifier];
if (!cell) {
if (row.generator != NULL) {
cell = row.generator(row.reuseIdentifier);
} else {
// no generator was specified, create a basic UITableViewCell
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:row.reuseIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
if (row.customizer) {
row.customizer(cell);
}
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return _allowsSwipeConfirmation;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
if (tableView != _searchResultsTableView && _showSectionIndexTitles) {
NSMutableArray *indexTitles = [NSMutableArray array];
for (BumpTableSection *section in _model.sections) {
[indexTitles addObject:section.indexTitle];
}
return indexTitles;
} else return nil;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return index;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [self sectionForIndex:section].header.title;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
return [self sectionForIndex:section].footer.title;
}
#pragma mark - UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [[self rowForTableView:tableView indexPath:indexPath] height];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (tableView == _searchResultsTableView) return 0.0;
return [[[self sectionForIndex:section] header] height];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (tableView == _searchResultsTableView) return 0.0;
return [[[self sectionForIndex:section] footer] height];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (tableView == _searchResultsTableView) return nil;
return [self sectionForIndex:section].header.view;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if (tableView == _searchResultsTableView) return nil;
return [self sectionForIndex:section].header.view;
}
- (void)reloadOtherTableView:(UITableView *)currentTableView {
UITableView *other;
if (currentTableView == _searchResultsTableView) {
other = _tableView;
} else {
other = _searchResultsTableView;
}
[other reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
BumpTableRow *row = [self rowForTableView:tableView indexPath:indexPath];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (row.onTap) {
row.onTap(cell);
//If you have search tableview you want to make sure it's contents are updated or vice versa
[self reloadOtherTableView:tableView];
}
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
BumpTableRow *row = [self rowForTableView:tableView indexPath:indexPath];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (row.onSwipeConfirmation) row.onSwipeConfirmation(cell);
}
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return _swipeConfirmationTitle;
}
#pragma mark - Helpers
+ (BumpTableSection *)sectionForIndex:(NSInteger)sectionIndex model:(BumpTableModel *)model {
return [[model sections] objectAtIndex:sectionIndex];
}
- (BumpTableSection *)sectionForIndex:(NSInteger)sectionIndex {
return [[self class] sectionForIndex:sectionIndex model:_model];
}
+ (BumpTableRow *)rowForIndexPath:(NSIndexPath *)indexPath model:(BumpTableModel *)model {
return [[[self sectionForIndex:indexPath.section model:model] rows] objectAtIndex:indexPath.row];
}
- (BumpTableRow *)rowForIndexPath:(NSIndexPath *)indexPath {
return [[self class] rowForIndexPath:indexPath model:_model];
}
- (BumpTableRow *)rowForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
if (tableView == _tableView) return [self rowForIndexPath:indexPath];
if (tableView == _searchResultsTableView) return [_searchResultsRows objectAtIndex:indexPath.row];
NSAssert(false, @"Unknown tableview");
return nil;
}
#pragma mark - Model changing
- (void)setModel:(BumpTableModel *)model {
_model = model;
if (_tableView) {
[_tableView reloadData];
}
}
- (void)transitionToModel:(BumpTableModel *)newModel {
UITableViewRowAnimation insertAnimation = _transitionAnimation;
UITableViewRowAnimation deleteAnimation = _transitionAnimation;
BumpTableModel *oldModel = _model;
_model = newModel;
if (!oldModel) {
[_tableView reloadData];
return;
}
if (!newModel) {
[_tableView deleteSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, oldModel.sections.count)]
withRowAnimation:deleteAnimation];
return;
}
BumpTransition *sectionInfo = [[self class] sectionTransitionFrom:oldModel.sections
to:newModel.sections];
NSDictionary *oldS = [oldModel sectionIndexes];//key->indexSet
NSAssert(oldS.count == oldModel.sections.count, @"the old table model has non-unique section keys");
NSDictionary *newS = [newModel sectionIndexes];
NSAssert(newS.count == newModel.sections.count, @"the new table model has non-unique section keys");
NSDictionary *oldIps = [oldModel rowIndexPaths];//key->indexPath if its a row
NSAssert(oldIps.count == oldS.count + [BumpTableUtils sumArray:oldModel.sections withBlock:^int(BumpTableSection *s) { return s.rows.count; }], @"the old table model has non-unique row keys");
NSDictionary *newIps = [newModel rowIndexPaths];//key->dict of k->ip if it's a section
NSAssert(newIps.count == newS.count + [BumpTableUtils sumArray:newModel.sections withBlock:^int(BumpTableSection *s) { return s.rows.count; }], @"the new table model has non-unique row keys");
BumpTransition *rowInfo = [[self class] rowTransitionFrom:oldModel to:newModel
fromSections:oldS toSections:newS
fromRows:oldIps toRows:newIps
sameSections:sectionInfo.mutual];
NSArray *thenVisibleIps = [_tableView indexPathsForVisibleRows];
// perform updates on tableview
[_tableView beginUpdates];
{
// perform any section insertions on the tableview
for (NSObject *key in sectionInfo.inserted) {
[_tableView insertSections:[newS objectForKey:key]
withRowAnimation:insertAnimation];
}
// perform any section deletions on the tableview
for (NSObject *key in sectionInfo.deleted) {
[_tableView deleteSections:[oldS objectForKey:key]
withRowAnimation:deleteAnimation];
}
// perform any section moves within the tableview
for (NSObject *key in sectionInfo.moved) {
[_tableView moveSection:[[oldS objectForKey:key] firstIndex]
toSection:[[newS objectForKey:key] firstIndex]];
}
// perform any row insertions on the tableview
[_tableView insertRowsAtIndexPaths:[newIps objectsForKeys:[rowInfo.inserted allObjects]
notFoundMarker:[NSNull null]]
withRowAnimation:insertAnimation];
// perform any row deletions on the tableview
[_tableView deleteRowsAtIndexPaths:[oldIps objectsForKeys:[rowInfo.deleted allObjects]
notFoundMarker:[NSNull null]]
withRowAnimation:deleteAnimation];
// perform any row moves in the tableview
for (NSObject *key in rowInfo.moved) {
[_tableView moveRowAtIndexPath:[oldIps objectForKey:key]
toIndexPath:[newIps objectForKey:key]];
}
}
[_tableView endUpdates];
NSArray *nowVisibleIps = [_tableView indexPathsForVisibleRows];
NSMutableArray *toReload = [NSMutableArray array];
for (NSIndexPath *ip in thenVisibleIps) {
BumpTableRow *oldRow = [[self class] rowForIndexPath:ip model:oldModel];
NSObject *key = [oldRow key];
NSIndexPath *newIp = [newIps objectForKey:key];
if (newIp && [nowVisibleIps containsObject:newIp]) {
BumpTableRow *row = [[self class] rowForIndexPath:newIp model:newModel];
if ([[row reuseIdentifier] isEqualToString:[oldRow reuseIdentifier]]) {
UITableViewCell *cell = [_tableView cellForRowAtIndexPath:newIp];
if (row.customizer) {
row.customizer(cell);
}
} else {
[toReload addObject:newIp];
}
}
}
if ([toReload count]) {
[_tableView reloadRowsAtIndexPaths:toReload withRowAnimation:UITableViewRowAnimationNone];
}
}
#pragma mark - Transitions helpers
- (void)setTransitionAnimation:(UITableViewRowAnimation)transitionAnimation {
_transitionAnimation = transitionAnimation;
}
/**
* This takes two arrays of keys and returns a set of mismatches
*/
+ (NSSet *)movedKeysFrom:(NSArray *)old to:(NSArray *)new {
NSMutableSet *moved = [NSMutableSet set];
int i;
for (i = 0; i < old.count && i < new.count; i++) {
NSObject *key = [old objectAtIndex:i];
if (![key isEqual:[new objectAtIndex:i]]) {
[moved addObject:key];
}
}
for (; i < old.count; i++) {//we hit the end of the other sections
[moved addObject:[old objectAtIndex:i]];
}
return moved;
}
+ (BumpTransition *)sectionTransitionFrom:(NSArray *)oldSections to:(NSArray *)newSections {
NSMutableSet *insertedSections = [NSMutableSet set];
NSMutableSet *deletedSections = [NSMutableSet set];
//calculate inserted and deleted sections
id (^secKeys)(id) = ^id(BumpTableSection *s) { return s.key; };
NSSet *oldSKeys = [NSSet setWithArray:[BumpTableUtils mapArray:oldSections
withBlock:secKeys]];
NSSet *newSKeys = [NSSet setWithArray:[BumpTableUtils mapArray:newSections
withBlock:secKeys]];
NSMutableSet *mutualSections = [NSMutableSet setWithSet:oldSKeys];
[mutualSections intersectSet:newSKeys];
[deletedSections unionSet:oldSKeys];
[deletedSections minusSet:mutualSections];
[insertedSections unionSet:newSKeys];
[insertedSections minusSet:mutualSections];
BOOL (^goodSecs)(id) = ^ BOOL(NSObject *key) {
return [mutualSections containsObject:key];
};
//calculate moved sections
NSSet *movedSections = [self movedKeysFrom:[BumpTableUtils filterArray:[BumpTableUtils mapArray:oldSections
withBlock:secKeys]
withBlock:goodSecs]
to:[BumpTableUtils filterArray:[BumpTableUtils mapArray:newSections
withBlock:secKeys]
withBlock:goodSecs]];
BumpTransition *sectionTransition = [BumpTransition new];
sectionTransition.inserted = insertedSections;
sectionTransition.deleted = deletedSections;
sectionTransition.mutual = mutualSections;
sectionTransition.moved = movedSections;
return sectionTransition;
}
+ (BumpTransition *)rowTransitionFrom:(BumpTableModel *)oldModel
to:(BumpTableModel *)newModel
fromSections:(NSDictionary *)oldSecIx
toSections:(NSDictionary *)newSecIx
fromRows:(NSDictionary *)oldIps
toRows:(NSDictionary *)newIps
sameSections:(NSSet *)mutualSections {
NSMutableSet *insertedRows = [NSMutableSet set];
NSMutableSet *deletedRows = [NSMutableSet set];
NSMutableSet *movedRows = [NSMutableSet set];
//check the sections that stay the same for inserted and deleted rows
//first make deleted and inserted supersets of actual deletions/ insertions
for (NSObject *key in mutualSections) {
NSDictionary *oldSectionIps = [oldIps objectForKey:key];
NSDictionary *newSectionIps = [newIps objectForKey:key];
NSAssert(oldSectionIps && newSectionIps, @"mutual section should be in old %@ and new %@", oldSectionIps, newSectionIps);
[deletedRows addObjectsFromArray:[oldSectionIps allKeys]];
[insertedRows addObjectsFromArray:[newSectionIps allKeys]];
}
NSMutableSet *mutualRows = [NSMutableSet setWithSet:deletedRows];
[mutualRows intersectSet:insertedRows];
//then subtract things that are the same
[deletedRows minusSet:mutualRows];
[insertedRows minusSet:mutualRows];
//check the rows for mismatched sections, add them to the moved rows
for (NSObject *key in mutualRows) {
NSIndexPath *oldIp = [oldIps objectForKey:key];
NSIndexPath *newIp = [newIps objectForKey:key];
NSAssert(oldIp && newIp, @"mutual row should have both old %@ and new %@ ips", oldIp, newIp);
BumpTableSection *oldSection = [self sectionForIndex:[oldIp section] model:oldModel];
BumpTableSection *newSection = [self sectionForIndex:[newIp section] model:newModel];
NSAssert(oldSection && newSection, @"mutual row should have old section %@ and new %@", oldSection, newSection);
if (![oldSection.key isEqual:newSection.key]) {
[movedRows addObject:key];
}
}
//compare the rows in the old model's sections to the new model's corresponding section
for (NSObject *key in mutualSections) {
NSIndexSet *oldSectionIx = [oldSecIx objectForKey:key];
NSIndexSet *newSectionIx = [newSecIx objectForKey:key];
NSAssert(oldSectionIx && newSectionIx, @"mutual row should have old sectionIx %@ and newIx %@", oldSectionIx, newSectionIx);
BumpTableSection *oldSection = [self sectionForIndex:[oldSectionIx firstIndex] model:oldModel];
BumpTableSection *newSection = [self sectionForIndex:[newSectionIx firstIndex] model:newModel];
NSAssert(oldSection && newSection, @"mutual row should have old section %@ and new %@", oldSection, newSection);
id (^rKey)(id) = ^(BumpTableRow *r) { return r.key; };
BOOL (^goodRow)(id) = ^BOOL(NSObject *key) {
return [mutualRows containsObject:key] && ![movedRows containsObject:key];
};
NSSet *movedInThisSection = [self movedKeysFrom:[BumpTableUtils filterArray:[BumpTableUtils mapArray:oldSection.rows
withBlock:rKey]
withBlock:goodRow]
to:[BumpTableUtils filterArray:[BumpTableUtils mapArray:newSection.rows
withBlock:rKey]
withBlock:goodRow]];
[movedRows unionSet:movedInThisSection];
}
BumpTransition *rowTransition = [BumpTransition new];
rowTransition.inserted = insertedRows;
rowTransition.deleted = deletedRows;
rowTransition.mutual = mutualRows;
rowTransition.moved = movedRows;
return rowTransition;
}
#pragma mark - Searching
- (UISearchBar *)searchBar {
if (!_searchBar) {
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,_tableView.frame.size.width, SEARCH_BAR_HEIGHT)];
_tableView.tableHeaderView = _searchBar;
}
return _searchBar;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
_searchResultsTableView = tableView;
_searchResultsTableView.backgroundColor = _tableView.backgroundColor;
_searchResultsTableView.separatorStyle = _tableView.separatorStyle;
tableView.delegate = self;
tableView.dataSource = self;
_searchResultsRows = [NSArray array];
}
- (void)searchDisplayController:(UISearchDisplayController *)controller willUnloadSearchResultsTableView:(UITableView *)tableView {
_searchResultsTableView = nil;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
NSMutableArray *newResults = [_model rowsForSearchString:searchString];
if ([newResults isEqual:_searchResultsRows]) {
return NO;
}
_searchResultsRows = newResults;
return YES;
}
#pragma mark - UIScrollViewDelegate passthroughs
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewDidScroll:scrollView];
}
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewDidZoom:scrollView];
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewWillBeginDragging:scrollView];
}
}
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset];
}
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewWillBeginDecelerating:scrollView];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewDidEndDecelerating:scrollView];
}
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewDidEndScrollingAnimation:scrollView];
}
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
return [self.scrollViewDelegate viewForZoomingInScrollView:scrollView];
}
return nil;
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewWillBeginZooming:scrollView withView:view];
}
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewDidEndZooming:scrollView withView:view atScale:scale];
}
}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
return [self.scrollViewDelegate scrollViewShouldScrollToTop:scrollView];
}
return YES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
if ([self.scrollViewDelegate respondsToSelector:_cmd]) {
[self.scrollViewDelegate scrollViewDidScrollToTop:scrollView];
}
}
@end