UITableView+YYAdd.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // UITableView+YYAdd.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 14/5/12.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. Provides extensions for `UITableView`.
  15. */
  16. @interface UITableView (YYAdd)
  17. /**
  18. Perform a series of method calls that insert, delete, or select rows and
  19. sections of the receiver.
  20. @discussion Perform a series of method calls that insert, delete, or select
  21. rows and sections of the table. Call this method if you want
  22. subsequent insertions, deletion, and selection operations (for
  23. example, cellForRowAtIndexPath: and indexPathsForVisibleRows)
  24. to be animated simultaneously.
  25. @discussion If you do not make the insertion, deletion, and selection calls
  26. inside this block, table attributes such as row count might become
  27. invalid. You should not call reloadData within the block; if you
  28. call this method within the group, you will need to perform any
  29. animations yourself.
  30. @param block A block combine a series of method calls.
  31. */
  32. - (void)updateWithBlock:(void (^)(UITableView *tableView))block;
  33. /**
  34. Scrolls the receiver until a row or section location on the screen.
  35. @discussion Invoking this method does not cause the delegate to
  36. receive a scrollViewDidScroll: message, as is normal for
  37. programmatically-invoked user interface operations.
  38. @param row Row index in section. NSNotFound is a valid value for
  39. scrolling to a section with zero rows.
  40. @param section Section index in table.
  41. @param scrollPosition A constant that identifies a relative position in the
  42. receiving table view (top, middle, bottom) for row when
  43. scrolling concludes.
  44. @param animated YES if you want to animate the change in position,
  45. NO if it should be immediate.
  46. */
  47. - (void)scrollToRow:(NSUInteger)row inSection:(NSUInteger)section atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
  48. /**
  49. Inserts a row in the receiver with an option to animate the insertion.
  50. @param row Row index in section.
  51. @param section Section index in table.
  52. @param animation A constant that either specifies the kind of animation to
  53. perform when inserting the cell or requests no animation.
  54. */
  55. - (void)insertRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
  56. /**
  57. Reloads the specified row using a certain animation effect.
  58. @param row Row index in section.
  59. @param section Section index in table.
  60. @param animation A constant that indicates how the reloading is to be animated,
  61. for example, fade out or slide out from the bottom. The animation
  62. constant affects the direction in which both the old and the
  63. new rows slide. For example, if the animation constant is
  64. UITableViewRowAnimationRight, the old rows slide out to the
  65. right and the new cells slide in from the right.
  66. */
  67. - (void)reloadRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
  68. /**
  69. Deletes the row with an option to animate the deletion.
  70. @param row Row index in section.
  71. @param section Section index in table.
  72. @param animation A constant that indicates how the deletion is to be animated,
  73. for example, fade out or slide out from the bottom.
  74. */
  75. - (void)deleteRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
  76. /**
  77. Inserts the row in the receiver at the locations identified by the indexPath,
  78. with an option to animate the insertion.
  79. @param indexPath An NSIndexPath object representing a row index and section
  80. index that together identify a row in the table view.
  81. @param animation A constant that either specifies the kind of animation to
  82. perform when inserting the cell or requests no animation.
  83. */
  84. - (void)insertRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
  85. /**
  86. Reloads the specified row using a certain animation effect.
  87. @param indexPath An NSIndexPath object representing a row index and section
  88. index that together identify a row in the table view.
  89. @param animation A constant that indicates how the reloading is to be animated,
  90. for example, fade out or slide out from the bottom. The animation
  91. constant affects the direction in which both the old and the
  92. new rows slide. For example, if the animation constant is
  93. UITableViewRowAnimationRight, the old rows slide out to the
  94. right and the new cells slide in from the right.
  95. */
  96. - (void)reloadRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
  97. /**
  98. Deletes the row specified by an array of index paths,
  99. with an option to animate the deletion.
  100. @param indexPath An NSIndexPath object representing a row index and section
  101. index that together identify a row in the table view.
  102. @param animation A constant that indicates how the deletion is to be animated,
  103. for example, fade out or slide out from the bottom.
  104. */
  105. - (void)deleteRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
  106. /**
  107. Inserts a section in the receiver, with an option to animate the insertion.
  108. @param section An index specifies the section to insert in the receiving
  109. table view. If a section already exists at the specified
  110. index location, it is moved down one index location.
  111. @param animation A constant that indicates how the insertion is to be animated,
  112. for example, fade in or slide in from the left.
  113. */
  114. - (void)insertSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
  115. /**
  116. Deletes a section in the receiver, with an option to animate the deletion.
  117. @param section An index that specifies the sections to delete from the
  118. receiving table view. If a section exists after the specified
  119. index location, it is moved up one index location.
  120. @param animation A constant that either specifies the kind of animation to
  121. perform when deleting the section or requests no animation.
  122. */
  123. - (void)deleteSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
  124. /**
  125. Reloads the specified section using a given animation effect.
  126. @param section An index identifying the section to reload.
  127. @param animation A constant that indicates how the reloading is to be animated,
  128. for example, fade out or slide out from the bottom. The
  129. animation constant affects the direction in which both the
  130. old and the new section rows slide. For example, if the
  131. animation constant is UITableViewRowAnimationRight, the old
  132. rows slide out to the right and the new cells slide in from the right.
  133. */
  134. - (void)reloadSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
  135. /**
  136. Unselect all rows in tableView.
  137. @param animated YES to animate the transition, NO to make the transition immediate.
  138. */
  139. - (void)clearSelectedRowsAnimated:(BOOL)animated;
  140. @end
  141. NS_ASSUME_NONNULL_END