AutocompletePushViewController.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2016 Google LLC. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompletePushViewController.h"
  16. #import <GooglePlaces/GooglePlaces.h>
  17. @interface AutocompletePushViewController () <GMSAutocompleteViewControllerDelegate>
  18. @end
  19. @implementation AutocompletePushViewController {
  20. UIButton *_showAutocompleteWidgetButton;
  21. }
  22. + (NSString *)demoTitle {
  23. return NSLocalizedString(
  24. @"Demo.Title.Autocomplete.Push",
  25. @"Title of the pushed autocomplete demo for display in a list or nav header");
  26. }
  27. #pragma mark - View Lifecycle
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Configure the UI. Tell our superclass we want a button and a result view below that.
  31. _showAutocompleteWidgetButton =
  32. [self createShowAutocompleteButton:@selector(showAutocompleteWidgetButtonTapped)];
  33. }
  34. #pragma mark - Creation of |GMSAutocompleteViewController| instance.
  35. - (GMSAutocompleteViewController *)autocompleteViewControllerInstance {
  36. GMSAutocompleteViewController *autocompleteViewController =
  37. [[GMSAutocompleteViewController alloc] init];
  38. autocompleteViewController.delegate = self;
  39. autocompleteViewController.autocompleteFilter = self.autocompleteFilter;
  40. autocompleteViewController.placeFields = self.placeFields;
  41. // Returns new GMSAutocompleteViewController instance.
  42. return autocompleteViewController;
  43. }
  44. #pragma mark - Actions
  45. - (IBAction)showAutocompleteWidgetButtonTapped {
  46. // When the button is tapped just push a new autocomplete view controller onto the stack.
  47. [self.navigationController pushViewController:[self autocompleteViewControllerInstance]
  48. animated:YES];
  49. [_showAutocompleteWidgetButton setHidden:YES];
  50. }
  51. #pragma mark - GMSAutocompleteViewControllerDelegate
  52. - (void)viewController:(GMSAutocompleteViewController *)viewController
  53. didAutocompleteWithPlace:(GMSPlace *)place {
  54. // Dismiss the view controller and tell our superclass to populate the result view.
  55. [self.navigationController popToViewController:self animated:YES];
  56. [self autocompleteDidSelectPlace:place];
  57. }
  58. - (void)viewController:(GMSAutocompleteViewController *)viewController
  59. didFailAutocompleteWithError:(NSError *)error {
  60. // Dismiss the view controller and notify our superclass of the failure.
  61. [self.navigationController popToViewController:self animated:YES];
  62. [self autocompleteDidFail:error];
  63. }
  64. - (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
  65. // Dismiss the controller and show a message that it was canceled.
  66. [self.navigationController popToViewController:self animated:YES];
  67. [self autocompleteDidCancel];
  68. }
  69. - (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
  70. [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  71. }
  72. - (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
  73. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
  74. }
  75. @end