GMSAutocompleteTableDataSource.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // GMSAutocompleteTableDataSource.h
  3. // Google Places SDK for iOS
  4. //
  5. // Copyright 2016 Google LLC
  6. //
  7. // Usage of this SDK is subject to the Google Maps/Google Earth APIs Terms of
  8. // Service: https://developers.google.com/maps/terms
  9. //
  10. #import <UIKit/UIKit.h>
  11. #import "GMSAutocompleteFilter.h"
  12. #import "GMSAutocompletePrediction.h"
  13. #import "GMSPlace.h"
  14. #import "GMSPlaceFieldMask.h"
  15. #import "GMSPlacesDeprecationUtils.h"
  16. @class GMSAutocompleteTableDataSource;
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * Protocol used by |GMSAutocompleteTableDataSource|, to communicate the user's interaction with the
  20. * data source to the application.
  21. */
  22. @protocol GMSAutocompleteTableDataSourceDelegate <NSObject>
  23. @required
  24. /**
  25. * Called when a place has been selected from the available autocomplete predictions.
  26. * @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
  27. * @param place The |GMSPlace| that was returned.
  28. */
  29. - (void)tableDataSource:(GMSAutocompleteTableDataSource *)tableDataSource
  30. didAutocompleteWithPlace:(GMSPlace *)place;
  31. /**
  32. * Called when a non-retryable error occurred when retrieving autocomplete predictions or place
  33. * details. A non-retryable error is defined as one that is unlikely to be fixed by immediately
  34. * retrying the operation.
  35. * <p>
  36. * Only the following values of |GMSPlacesErrorCode| are retryable:
  37. * <ul>
  38. * <li>kGMSPlacesNetworkError
  39. * <li>kGMSPlacesServerError
  40. * <li>kGMSPlacesInternalError
  41. * </ul>
  42. * All other error codes are non-retryable.
  43. * @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
  44. * @param error The |NSError| that was returned.
  45. */
  46. - (void)tableDataSource:(GMSAutocompleteTableDataSource *)tableDataSource
  47. didFailAutocompleteWithError:(NSError *)error;
  48. @optional
  49. /**
  50. * Called when the user selects an autocomplete prediction from the list but before requesting
  51. * place details. Returning NO from this method will suppress the place details fetch and
  52. * didAutocompleteWithPlace will not be called.
  53. * @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
  54. * @param prediction The |GMSAutocompletePrediction| that was selected.
  55. */
  56. - (BOOL)tableDataSource:(GMSAutocompleteTableDataSource *)tableDataSource
  57. didSelectPrediction:(GMSAutocompletePrediction *)prediction;
  58. /**
  59. * Called once every time new autocomplete predictions are received.
  60. * @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
  61. */
  62. - (void)didUpdateAutocompletePredictionsForTableDataSource:
  63. (GMSAutocompleteTableDataSource *)tableDataSource;
  64. /**
  65. * Called once immediately after a request for autocomplete predictions is made.
  66. * @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
  67. */
  68. - (void)didRequestAutocompletePredictionsForTableDataSource:
  69. (GMSAutocompleteTableDataSource *)tableDataSource;
  70. @end
  71. /**
  72. * GMSAutocompleteTableDataSource provides an interface for providing place autocomplete
  73. * predictions to populate a UITableView by implementing the UITableViewDataSource and
  74. * UITableViewDelegate protocols.
  75. *
  76. * GMSAutocompleteTableDataSource is designed to be used as the data source for a
  77. * UISearchDisplayController.
  78. *
  79. * NOTE: UISearchDisplayController has been deprecated since iOS 8. It is now recommended to use
  80. * UISearchController with |GMSAutocompleteResultsViewController| to display autocomplete results
  81. * using the iOS search UI.
  82. *
  83. * Set an instance of GMSAutocompleteTableDataSource as the searchResultsDataSource and
  84. * searchResultsDelegate properties of UISearchDisplayController. In your implementation of
  85. * shouldReloadTableForSearchString, call sourceTextHasChanged with the current search string.
  86. *
  87. * Use the |GMSAutocompleteTableDataSourceDelegate| delegate protocol to be notified when a place is
  88. * selected from the list. Because autocomplete predictions load asynchronously, it is necessary
  89. * to implement didUpdateAutocompletePredictions and call reloadData on the
  90. * UISearchDisplayController's table view.
  91. *
  92. */
  93. @interface GMSAutocompleteTableDataSource : NSObject <UITableViewDataSource, UITableViewDelegate>
  94. /** Delegate to be notified when a place is selected or picking is cancelled. */
  95. @property(nonatomic, weak, nullable) IBOutlet id<GMSAutocompleteTableDataSourceDelegate> delegate;
  96. /** Filter to apply to autocomplete suggestions (can be nil). */
  97. @property(nonatomic, strong, nullable) GMSAutocompleteFilter *autocompleteFilter;
  98. /** The background color of table cells. */
  99. @property(nonatomic, strong) UIColor *tableCellBackgroundColor;
  100. /** The color of the separator line between table cells. */
  101. @property(nonatomic, strong) UIColor *tableCellSeparatorColor;
  102. /** The color of result name text in autocomplete results */
  103. @property(nonatomic, strong) UIColor *primaryTextColor;
  104. /** The color used to highlight matching text in autocomplete results */
  105. @property(nonatomic, strong) UIColor *primaryTextHighlightColor;
  106. /** The color of the second row of text in autocomplete results. */
  107. @property(nonatomic, strong) UIColor *secondaryTextColor;
  108. /** The tint color applied to controls in the Autocomplete view. */
  109. @property(nonatomic, strong, nullable) UIColor *tintColor;
  110. /**
  111. * The |GMSPlaceField| for specifying explicit place details to be requested. Default returns
  112. * all available fields.
  113. */
  114. @property(nonatomic, assign) GMSPlaceField placeFields;
  115. /** Designated initializer */
  116. - (instancetype)init NS_DESIGNATED_INITIALIZER;
  117. /**
  118. * Notify the data source that the source text to autocomplete has changed.
  119. *
  120. * This method should only be called from the main thread. Calling this method from another thread
  121. * will result in undefined behavior. Calls to |GMSAutocompleteTableDataSourceDelegate| methods will
  122. * also be called on the main thread.
  123. *
  124. * This method is non-blocking.
  125. * @param text The partial text to autocomplete.
  126. */
  127. - (void)sourceTextHasChanged:(nullable NSString *)text;
  128. /**
  129. * Clear all predictions.
  130. *
  131. * NOTE: This will call the two delegate methods below:
  132. *
  133. * - |didUpdateAutocompletePredictionsForResultsController:|
  134. * - |didRequestAutocompletePredictionsForResultsController:|
  135. *
  136. * The implementation of this method is guaranteed to call these synchronously and in-order.
  137. */
  138. - (void)clearResults;
  139. @end
  140. NS_ASSUME_NONNULL_END