Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Abstract</h2> <p>To avoid map being shown prematurely, you should actually wait for the asynchronous update operation, and the cleanest pattern to do so will be <strong>delegation</strong>. Here is <a href="https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html" rel="nofollow">a nice Apple Doc</a> on its application in Cocoa/Cocoa Touch.</p> <p>Then it will work roughly like this:</p> <ol> <li>Pull-to-Refresh triggers location update.</li> <li>When location update is finished, <code>locationManager</code> notifies your controller and the controller presents a map.</li> </ol> <h2>How it can be done</h2> <p>I don't know the interface of your location manager class, but if it was CLLocationManager, it could have been done this way.</p> <p>CLLocationManager has a delegate property. Your view controller should: </p> <ol> <li>conform to <a href="https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html#//apple_ref/occ/intf/CLLocationManagerDelegate" rel="nofollow">CLLocationManagerDelegate protocol</a></li> <li>add itself as a delegate to <code>locationManager</code></li> <li>implement <code>locationManager:didUpdateLocations:</code> method — it gets called when location data has arrived and is ready for use.</li> </ol> <p>The implementation of this method should look like roughly this: </p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { /* * shouldShowMap — BOOL property of View Controller, actually optional * but allowing to filter out handling of unwanted location updates * so they will not trigger map segue every time */ if (self.shouldShowMap) { [self performSegueWithIdentifier:@"showMap" sender:self]; self.shouldShowMap = NO; } // stop updating location — you need only one update, not a stream of consecutive updates [self.locationManager stopUpdatingLocation]; } </code></pre> <p>Your Pull-to-Refresh handler should look like this:</p> <pre><code>__typeof (&amp;*self) __weak weakSelf = self; [self.scrollView addPullToRefreshWithActionHandler:^ { self.shouldShowMap = YES; [weakSelf.locationManager startUpdatingLocation]; }]; </code></pre> <p>Hope it helped a bit. The best way to learn (well, in <em>most</em> cases) is to look at how stuff is implemented in system frameworks. Think in that direction and you'll definitely come up with a solution :)</p> <p>If you need clarifications, feel free to ask, I might have not explained it clearly enough.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload