ASTableNode.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. //
  2. // ASTableNode.h
  3. // AsyncDisplayKit
  4. //
  5. // Created by Steven Ramkumar on 11/4/15.
  6. //
  7. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8. // This source code is licensed under the BSD-style license found in the
  9. // LICENSE file in the root directory of this source tree. An additional grant
  10. // of patent rights can be found in the PATENTS file in the same directory.
  11. //
  12. #import <AsyncDisplayKit/ASTableView.h>
  13. #import <AsyncDisplayKit/ASDisplayNode.h>
  14. #import <AsyncDisplayKit/ASRangeControllerUpdateRangeProtocol+Beta.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. @protocol ASTableDataSource;
  17. @protocol ASTableDelegate;
  18. @class ASTableView;
  19. /**
  20. * ASTableNode is a node based class that wraps an ASTableView. It can be used
  21. * as a subnode of another node, and provide room for many (great) features and improvements later on.
  22. */
  23. @interface ASTableNode : ASDisplayNode <ASRangeControllerUpdateRangeProtocol>
  24. - (instancetype)init; // UITableViewStylePlain
  25. - (instancetype)initWithStyle:(UITableViewStyle)style;
  26. @property (strong, nonatomic, readonly) ASTableView *view;
  27. // These properties can be set without triggering the view to be created, so it's fine to set them in -init.
  28. @property (weak, nonatomic) id <ASTableDelegate> delegate;
  29. @property (weak, nonatomic) id <ASTableDataSource> dataSource;
  30. /*
  31. * A Boolean value that determines whether the table will be flipped.
  32. * If the value of this property is YES, the first cell node will be at the bottom of the table (as opposed to the top by default). This is useful for chat/messaging apps. The default value is NO.
  33. */
  34. @property (nonatomic, assign) BOOL inverted;
  35. /*
  36. * A Boolean value that determines whether users can select a row.
  37. * If the value of this property is YES (the default), users can select rows. If you set it to NO, they cannot select rows. Setting this property affects cell selection only when the table view is not in editing mode. If you want to restrict selection of cells in editing mode, use `allowsSelectionDuringEditing`.
  38. */
  39. @property (nonatomic, assign) BOOL allowsSelection;
  40. /*
  41. * A Boolean value that determines whether users can select cells while the table view is in editing mode.
  42. * If the value of this property is YES, users can select rows during editing. The default value is NO. If you want to restrict selection of cells regardless of mode, use allowsSelection.
  43. */
  44. @property (nonatomic, assign) BOOL allowsSelectionDuringEditing;
  45. /*
  46. * A Boolean value that determines whether users can select more than one row outside of editing mode.
  47. * This property controls whether multiple rows can be selected simultaneously outside of editing mode. When the value of this property is YES, each row that is tapped acquires a selected appearance. Tapping the row again removes the selected appearance. If you access indexPathsForSelectedRows, you can get the index paths that identify the selected rows.
  48. */
  49. @property (nonatomic, assign) BOOL allowsMultipleSelection;
  50. /*
  51. * A Boolean value that controls whether users can select more than one cell simultaneously in editing mode.
  52. * The default value of this property is NO. If you set it to YES, check marks appear next to selected rows in editing mode. In addition, UITableView does not query for editing styles when it goes into editing mode. If you access indexPathsForSelectedRows, you can get the index paths that identify the selected rows.
  53. */
  54. @property (nonatomic, assign) BOOL allowsMultipleSelectionDuringEditing;
  55. /**
  56. * Tuning parameters for a range type in full mode.
  57. *
  58. * @param rangeType The range type to get the tuning parameters for.
  59. *
  60. * @return A tuning parameter value for the given range type in full mode.
  61. *
  62. * @see ASLayoutRangeMode
  63. * @see ASLayoutRangeType
  64. */
  65. - (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT;
  66. /**
  67. * Set the tuning parameters for a range type in full mode.
  68. *
  69. * @param tuningParameters The tuning parameters to store for a range type.
  70. * @param rangeType The range type to set the tuning parameters for.
  71. *
  72. * @see ASLayoutRangeMode
  73. * @see ASLayoutRangeType
  74. */
  75. - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType;
  76. /**
  77. * Tuning parameters for a range type in the specified mode.
  78. *
  79. * @param rangeMode The range mode to get the running parameters for.
  80. * @param rangeType The range type to get the tuning parameters for.
  81. *
  82. * @return A tuning parameter value for the given range type in the given mode.
  83. *
  84. * @see ASLayoutRangeMode
  85. * @see ASLayoutRangeType
  86. */
  87. - (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT;
  88. /**
  89. * Set the tuning parameters for a range type in the specified mode.
  90. *
  91. * @param tuningParameters The tuning parameters to store for a range type.
  92. * @param rangeMode The range mode to set the running parameters for.
  93. * @param rangeType The range type to set the tuning parameters for.
  94. *
  95. * @see ASLayoutRangeMode
  96. * @see ASLayoutRangeType
  97. */
  98. - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType;
  99. /**
  100. * Scrolls the table to the given row.
  101. *
  102. * @param indexPath The index path of the row.
  103. * @param scrollPosition Where the row should end up after the scroll.
  104. * @param animated Whether the scroll should be animated or not.
  105. *
  106. * This method must be called on the main thread.
  107. */
  108. - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
  109. /**
  110. * Reload everything from scratch, destroying the working range and all cached nodes.
  111. *
  112. * @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
  113. * the main thread.
  114. * @warning This method is substantially more expensive than UITableView's version.
  115. */
  116. - (void)reloadDataWithCompletion:(nullable void (^)())completion;
  117. /**
  118. * Reload everything from scratch, destroying the working range and all cached nodes.
  119. *
  120. * @warning This method is substantially more expensive than UITableView's version.
  121. */
  122. - (void)reloadData;
  123. /**
  124. * Triggers a relayout of all nodes.
  125. *
  126. * @discussion This method invalidates and lays out every cell node in the table view.
  127. */
  128. - (void)relayoutItems;
  129. /**
  130. * Perform a batch of updates asynchronously, optionally disabling all animations in the batch. This method must be called from the main thread.
  131. * The data source must be updated to reflect the changes before the update block completes.
  132. *
  133. * @param animated NO to disable animations for this batch
  134. * @param updates The block that performs the relevant insert, delete, reload, or move operations.
  135. * @param completion A completion handler block to execute when all of the operations are finished. This block takes a single
  136. * Boolean parameter that contains the value YES if all of the related animations completed successfully or
  137. * NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
  138. */
  139. - (void)performBatchAnimated:(BOOL)animated updates:(nullable AS_NOESCAPE void (^)())updates completion:(nullable void (^)(BOOL finished))completion;
  140. /**
  141. * Perform a batch of updates asynchronously, optionally disabling all animations in the batch. This method must be called from the main thread.
  142. * The data source must be updated to reflect the changes before the update block completes.
  143. *
  144. * @param updates The block that performs the relevant insert, delete, reload, or move operations.
  145. * @param completion A completion handler block to execute when all of the operations are finished. This block takes a single
  146. * Boolean parameter that contains the value YES if all of the related animations completed successfully or
  147. * NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
  148. */
  149. - (void)performBatchUpdates:(nullable AS_NOESCAPE void (^)())updates completion:(nullable void (^)(BOOL finished))completion;
  150. /**
  151. * Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
  152. */
  153. - (void)waitUntilAllUpdatesAreCommitted;
  154. /**
  155. * Inserts one or more sections, with an option to animate the insertion.
  156. *
  157. * @param sections An index set that specifies the sections to insert.
  158. *
  159. * @param animation A constant that indicates how the insertion is to be animated. See UITableViewRowAnimation.
  160. *
  161. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  162. * before this method is called.
  163. */
  164. - (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
  165. /**
  166. * Deletes one or more sections, with an option to animate the deletion.
  167. *
  168. * @param sections An index set that specifies the sections to delete.
  169. *
  170. * @param animation A constant that indicates how the deletion is to be animated. See UITableViewRowAnimation.
  171. *
  172. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  173. * before this method is called.
  174. */
  175. - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
  176. /**
  177. * Reloads the specified sections using a given animation effect.
  178. *
  179. * @param sections An index set that specifies the sections to reload.
  180. *
  181. * @param animation A constant that indicates how the reloading is to be animated. See UITableViewRowAnimation.
  182. *
  183. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  184. * before this method is called.
  185. */
  186. - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
  187. /**
  188. * Moves a section to a new location.
  189. *
  190. * @param section The index of the section to move.
  191. *
  192. * @param newSection The index that is the destination of the move for the section.
  193. *
  194. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  195. * before this method is called.
  196. */
  197. - (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;
  198. /**
  199. * Inserts rows at the locations identified by an array of index paths, with an option to animate the insertion.
  200. *
  201. * @param indexPaths An array of NSIndexPath objects, each representing a row index and section index that together identify a row.
  202. *
  203. * @param animation A constant that indicates how the insertion is to be animated. See UITableViewRowAnimation.
  204. *
  205. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  206. * before this method is called.
  207. */
  208. - (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
  209. /**
  210. * Deletes the rows specified by an array of index paths, with an option to animate the deletion.
  211. *
  212. * @param indexPaths An array of NSIndexPath objects identifying the rows to delete.
  213. *
  214. * @param animation A constant that indicates how the deletion is to be animated. See UITableViewRowAnimation.
  215. *
  216. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  217. * before this method is called.
  218. */
  219. - (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
  220. /**
  221. * Reloads the specified rows using a given animation effect.
  222. *
  223. * @param indexPaths An array of NSIndexPath objects identifying the rows to reload.
  224. *
  225. * @param animation A constant that indicates how the reloading is to be animated. See UITableViewRowAnimation.
  226. *
  227. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  228. * before this method is called.
  229. */
  230. - (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
  231. /**
  232. * Moves the row at a specified location to a destination location.
  233. *
  234. * @param indexPath The index path identifying the row to move.
  235. *
  236. * @param newIndexPath The index path that is the destination of the move for the row.
  237. *
  238. * @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
  239. * before this method is called.
  240. */
  241. - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
  242. #pragma mark - Selection
  243. /**
  244. * Selects a row in the table view identified by index path, optionally scrolling the row to a location in the table view.
  245. * This method does not cause any selection-related delegate methods to be called.
  246. *
  247. * @param indexPath An index path identifying a row in the table view.
  248. *
  249. * @param animated Specify YES to animate the change in the selection or NO to make the change without animating it.
  250. *
  251. * @param scrollPosition A constant that identifies a relative position in the table view (top, middle, bottom) for the row when scrolling concludes. See `UITableViewScrollPosition` for descriptions of valid constants.
  252. *
  253. * @discussion This method must be called from the main thread.
  254. */
  255. - (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
  256. /*
  257. * Deselects a given row identified by index path, with an option to animate the deselection.
  258. * This method does not cause any selection-related delegate methods to be called.
  259. * Calling this method does not cause any scrolling to the deselected row.
  260. *
  261. * @param indexPath An index path identifying a row in the table view.
  262. *
  263. * @param animated Specify YES to animate the change in the selection or NO to make the change without animating it.
  264. *
  265. * @discussion This method must be called from the main thread.
  266. */
  267. - (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
  268. #pragma mark - Querying Data
  269. /**
  270. * Retrieves the number of rows in the given section.
  271. *
  272. * @param section The section.
  273. *
  274. * @return The number of rows.
  275. */
  276. - (NSInteger)numberOfRowsInSection:(NSInteger)section AS_WARN_UNUSED_RESULT;
  277. /**
  278. * The number of sections in the table node.
  279. */
  280. @property (nonatomic, readonly) NSInteger numberOfSections;
  281. /**
  282. * Similar to -visibleCells.
  283. *
  284. * @return an array containing the nodes being displayed on screen. This must be called on the main thread.
  285. */
  286. @property (nonatomic, readonly) NSArray<__kindof ASCellNode *> *visibleNodes;
  287. /**
  288. * Retrieves the node for the row at the given index path.
  289. */
  290. - (nullable __kindof ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
  291. /**
  292. * Similar to -indexPathForCell:.
  293. *
  294. * @param cellNode a node for a row.
  295. *
  296. * @return The index path to this row, if it exists.
  297. *
  298. * @discussion This method will return @c nil for a node that is still being
  299. * displayed in the table view, if the data source has deleted the row.
  300. * That is, the node is visible but it no longer corresponds
  301. * to any item in the data source and will be removed soon.
  302. */
  303. - (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode AS_WARN_UNUSED_RESULT;
  304. /**
  305. * Similar to -[UITableView rectForRowAtIndexPath:]
  306. *
  307. * @param indexPath An index path identifying a row in the table view.
  308. *
  309. * @return A rectangle defining the area in which the table view draws the row or CGRectZero if indexPath is invalid.
  310. *
  311. * @discussion This method must be called from the main thread.
  312. */
  313. - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
  314. /**
  315. * Similar to -[UITableView cellForRowAtIndexPath:]
  316. *
  317. * @param indexPath An index path identifying a row in the table view.
  318. *
  319. * @return An object representing a cell of the table, or nil if the cell is not visible or indexPath is out of range.
  320. *
  321. * @discussion This method must be called from the main thread.
  322. */
  323. - (nullable __kindof UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
  324. /**
  325. * Similar to UITableView.indexPathForSelectedRow
  326. *
  327. * @return The value of this property is an index path identifying the row and section
  328. * indexes of the selected row, or nil if the index path is invalid. If there are multiple selections,
  329. * this property contains the first index-path object in the array of row selections;
  330. * this object has the lowest index values for section and row.
  331. *
  332. * @discussion This method must be called from the main thread.
  333. */
  334. @property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow;
  335. @property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForSelectedRows;
  336. /**
  337. * Similar to -[UITableView indexPathForRowAtPoint:]
  338. *
  339. * @param point A point in the local coordinate system of the table view (the table view’€™s bounds).
  340. *
  341. * @return An index path representing the row and section associated with point,
  342. * or nil if the point is out of the bounds of any row.
  343. *
  344. * @discussion This method must be called from the main thread.
  345. */
  346. - (nullable NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point AS_WARN_UNUSED_RESULT;
  347. /**
  348. * Similar to -[UITableView indexPathsForRowsInRect:]
  349. *
  350. * @param rect A rectangle defining an area of the table view in local coordinates.
  351. *
  352. * @return An array of NSIndexPath objects each representing a row and section index identifying a row within rect.
  353. * Returns an empty array if there aren’t any rows to return.
  354. *
  355. * @discussion This method must be called from the main thread.
  356. */
  357. - (nullable NSArray<NSIndexPath *> *)indexPathsForRowsInRect:(CGRect)rect AS_WARN_UNUSED_RESULT;
  358. /**
  359. * Similar to -[UITableView indexPathsForVisibleRows]
  360. *
  361. * @return The value of this property is an array of NSIndexPath objects each representing a row index and section index
  362. * that together identify a visible row in the table view. If no rows are visible, the value is nil.
  363. *
  364. * @discussion This method must be called from the main thread.
  365. */
  366. - (NSArray<NSIndexPath *> *)indexPathsForVisibleRows AS_WARN_UNUSED_RESULT;
  367. @end
  368. /**
  369. * This is a node-based UITableViewDataSource.
  370. */
  371. @protocol ASTableDataSource <ASCommonTableDataSource, NSObject>
  372. @optional
  373. /**
  374. * Asks the data source for the number of sections in the table node.
  375. *
  376. * @see @c numberOfSectionsInTableView:
  377. */
  378. - (NSInteger)numberOfSectionsInTableNode:(ASTableNode *)tableNode;
  379. /**
  380. * Asks the data source for the number of rows in the given section of the table node.
  381. *
  382. * @see @c numberOfSectionsInTableView:
  383. */
  384. - (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section;
  385. /**
  386. * Asks the data source for a block to create a node to represent the row at the given index path.
  387. * The block will be run by the table node concurrently in the background before the row is inserted
  388. * into the table view.
  389. *
  390. * @param tableNode The sender.
  391. * @param indexPath The index path of the row.
  392. *
  393. * @return a block that creates the node for display at this indexpath.
  394. * Must be thread-safe (can be called on the main thread or a background
  395. * queue) and should not implement reuse (it will be called once per row).
  396. *
  397. * @note This method takes precedence over tableNode:nodeForRowAtIndexPath: if implemented.
  398. */
  399. - (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath;
  400. /**
  401. * Asks the data source for a node to represent the row at the given index path.
  402. *
  403. * @param tableNode The sender.
  404. * @param indexPath The index path of the row.
  405. *
  406. * @return a node to display for this row. This will be called on the main thread and should not implement reuse (it will be called once per row). Unlike UITableView's version, this method
  407. * is not called when the row is about to display.
  408. */
  409. - (ASCellNode *)tableNode:(ASTableNode *)tableNode nodeForRowAtIndexPath:(NSIndexPath *)indexPath;
  410. /**
  411. * Similar to -tableView:cellForRowAtIndexPath:.
  412. *
  413. * @param tableNode The sender.
  414. *
  415. * @param indexPath The index path of the requested node.
  416. *
  417. * @return a node for display at this indexpath. This will be called on the main thread and should not implement reuse (it will be called once per row). Unlike UITableView's version, this method
  418. * is not called when the row is about to display.
  419. */
  420. - (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  421. /**
  422. * Similar to -tableView:nodeForRowAtIndexPath:
  423. * This method takes precedence over tableView:nodeForRowAtIndexPath: if implemented.
  424. * @param tableView The sender.
  425. *
  426. * @param indexPath The index path of the requested node.
  427. *
  428. * @return a block that creates the node for display at this indexpath.
  429. * Must be thread-safe (can be called on the main thread or a background
  430. * queue) and should not implement reuse (it will be called once per row).
  431. */
  432. - (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  433. /**
  434. * Indicator to lock the data source for data fetching in async mode.
  435. * We should not update the data source until the data source has been unlocked. Otherwise, it will incur data inconsistency or exception
  436. * due to the data access in async mode.
  437. *
  438. * @param tableView The sender.
  439. * @deprecated The data source is always accessed on the main thread, and this method will not be called.
  440. */
  441. - (void)tableViewLockDataSource:(ASTableView *)tableView ASDISPLAYNODE_DEPRECATED_MSG("Data source accesses are on the main thread. Method will not be called.");
  442. /**
  443. * Indicator to unlock the data source for data fetching in asyn mode.
  444. * We should not update the data source until the data source has been unlocked. Otherwise, it will incur data inconsistency or exception
  445. * due to the data access in async mode.
  446. *
  447. * @param tableView The sender.
  448. * @deprecated The data source is always accessed on the main thread, and this method will not be called.
  449. */
  450. - (void)tableViewUnlockDataSource:(ASTableView *)tableView ASDISPLAYNODE_DEPRECATED_MSG("Data source accesses are on the main thread. Method will not be called.");
  451. @end
  452. /**
  453. * This is a node-based UITableViewDelegate.
  454. *
  455. * Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are
  456. * responsible for deciding their preferred onscreen height in -calculateSizeThatFits:.
  457. */
  458. @protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject>
  459. @optional
  460. - (void)tableNode:(ASTableNode *)tableNode willDisplayRowWithNode:(ASCellNode *)node;
  461. - (void)tableNode:(ASTableNode *)tableNode didEndDisplayingRowWithNode:(ASCellNode *)node;
  462. - (nullable NSIndexPath *)tableNode:(ASTableNode *)tableNode willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
  463. - (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
  464. - (nullable NSIndexPath *)tableNode:(ASTableNode *)tableNode willDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
  465. - (void)tableNode:(ASTableNode *)tableNode didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
  466. - (BOOL)tableNode:(ASTableNode *)tableNode shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath;
  467. - (void)tableNode:(ASTableNode *)tableNode didHighlightRowAtIndexPath:(NSIndexPath *)indexPath;
  468. - (void)tableNode:(ASTableNode *)tableNode didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath;
  469. - (BOOL)tableNode:(ASTableNode *)tableNode shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath;
  470. - (BOOL)tableNode:(ASTableNode *)tableNode canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(nullable id)sender;
  471. - (void)tableNode:(ASTableNode *)tableNode performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(nullable id)sender;
  472. /**
  473. * Provides the constrained size range for measuring the row at the index path.
  474. * Note: the widths in the returned size range are ignored!
  475. *
  476. * @param tableNode The sender.
  477. *
  478. * @param indexPath The index path of the node.
  479. *
  480. * @return A constrained size range for layout the node at this index path.
  481. */
  482. - (ASSizeRange)tableNode:(ASTableNode *)tableNode constrainedSizeForRowAtIndexPath:(NSIndexPath *)indexPath;
  483. /**
  484. * Receive a message that the tableView is near the end of its data set and more data should be fetched if necessary.
  485. *
  486. * @param tableView The sender.
  487. * @param context A context object that must be notified when the batch fetch is completed.
  488. *
  489. * @discussion You must eventually call -completeBatchFetching: with an argument of YES in order to receive future
  490. * notifications to do batch fetches. This method is called on a background queue.
  491. *
  492. * ASTableView currently only supports batch events for tail loads. If you require a head load, consider implementing a
  493. * UIRefreshControl.
  494. */
  495. - (void)tableNode:(ASTableNode *)tableNode willBeginBatchFetchWithContext:(ASBatchContext *)context;
  496. /**
  497. * Tell the tableView if batch fetching should begin.
  498. *
  499. * @param tableView The sender.
  500. *
  501. * @discussion Use this method to conditionally fetch batches. Example use cases are: limiting the total number of
  502. * objects that can be fetched or no network connection.
  503. *
  504. * If not implemented, the tableView assumes that it should notify its asyncDelegate when batch fetching
  505. * should occur.
  506. */
  507. - (BOOL)shouldBatchFetchForTableNode:(ASTableNode *)tableNode;
  508. /**
  509. * Informs the delegate that the table view will add the given node
  510. * at the given index path to the view hierarchy.
  511. *
  512. * @param tableView The sender.
  513. * @param node The node that will be displayed.
  514. * @param indexPath The index path of the row that will be displayed.
  515. *
  516. * @warning AsyncDisplayKit processes table view edits asynchronously. The index path
  517. * passed into this method may not correspond to the same item in your data source
  518. * if your data source has been updated since the last edit was processed.
  519. */
  520. - (void)tableView:(ASTableView *)tableView willDisplayNode:(ASCellNode *)node forRowAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  521. /**
  522. * Informs the delegate that the table view did remove the provided node from the view hierarchy.
  523. * This may be caused by the node scrolling out of view, or by deleting the row
  524. * or its containing section with @c deleteRowsAtIndexPaths:withRowAnimation: or @c deleteSections:withRowAnimation: .
  525. *
  526. * @param tableView The sender.
  527. * @param node The node which was removed from the view hierarchy.
  528. * @param indexPath The index path at which the node was located before the removal.
  529. *
  530. * @warning AsyncDisplayKit processes table view edits asynchronously. The index path
  531. * passed into this method may not correspond to the same item in your data source
  532. * if your data source has been updated since the last edit was processed.
  533. */
  534. - (void)tableView:(ASTableView *)tableView didEndDisplayingNode:(ASCellNode *)node forRowAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  535. /**
  536. * Receive a message that the tableView is near the end of its data set and more data should be fetched if necessary.
  537. *
  538. * @param tableView The sender.
  539. * @param context A context object that must be notified when the batch fetch is completed.
  540. *
  541. * @discussion You must eventually call -completeBatchFetching: with an argument of YES in order to receive future
  542. * notifications to do batch fetches. This method is called on a background queue.
  543. *
  544. * ASTableView currently only supports batch events for tail loads. If you require a head load, consider implementing a
  545. * UIRefreshControl.
  546. */
  547. - (void)tableView:(ASTableView *)tableView willBeginBatchFetchWithContext:(ASBatchContext *)context ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  548. /**
  549. * Tell the tableView if batch fetching should begin.
  550. *
  551. * @param tableView The sender.
  552. *
  553. * @discussion Use this method to conditionally fetch batches. Example use cases are: limiting the total number of
  554. * objects that can be fetched or no network connection.
  555. *
  556. * If not implemented, the tableView assumes that it should notify its asyncDelegate when batch fetching
  557. * should occur.
  558. */
  559. - (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  560. /**
  561. * Provides the constrained size range for measuring the row at the index path.
  562. * Note: the widths in the returned size range are ignored!
  563. *
  564. * @param tableView The sender.
  565. *
  566. * @param indexPath The index path of the node.
  567. *
  568. * @return A constrained size range for layout the node at this index path.
  569. */
  570. - (ASSizeRange)tableView:(ASTableView *)tableView constrainedSizeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  571. /**
  572. * Informs the delegate that the table view will add the node
  573. * at the given index path to the view hierarchy.
  574. *
  575. * @param tableView The sender.
  576. * @param indexPath The index path of the row that will be displayed.
  577. *
  578. * @warning AsyncDisplayKit processes table view edits asynchronously. The index path
  579. * passed into this method may not correspond to the same item in your data source
  580. * if your data source has been updated since the last edit was processed.
  581. *
  582. * This method is deprecated. Use @c tableView:willDisplayNode:forRowAtIndexPath: instead.
  583. */
  584. - (void)tableView:(ASTableView *)tableView willDisplayNodeForRowAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's method instead.");
  585. @end
  586. NS_ASSUME_NONNULL_END