ios - 使用后台线程从 url 加载注释。在移动或缩放 mapView 之前,引脚不显示
<p><p>我使用后台线程从 url 加载注释。在我移动或缩放 mapView 之前,图钉不显示。如何更新我的 View ?</p>
<p>我的 viewDidAppear</p>
<pre><code>- (void)viewDidAppear:(BOOL)animated
{
;
//Create the thread
;
}
</code></pre>
<p>加载PList</p>
<pre><code>- (void) loadPList { //Load the plist NSString *urlStr = [ initWithFormat:@"http://www.domain.com/data.xml"];
NSURL *url = ; NSDictionary *dict = [ initWithContentsOfURL:url];
NSMutableArray *annotations = [init];
NSArray *annotationsOnMap = mapView.annotations; if ( > ) { ;
} else { //Do nothing }
if ([ boolForKey:@"blackKey"]) {
NSArray *ann = ;
for(int i = 0; i < ; i++) {
NSString *coordinates = [ objectForKey:@"Coordinates"];
double realLatitude = [[ objectAtIndex:1] doubleValue];
double realLongitude = [[ objectAtIndex:0] doubleValue];
MyAnnotation *myAnnotation = [ init];
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = realLatitude;
theCoordinate.longitude = realLongitude;
myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);
myAnnotation.title = [ objectForKey:@"Name"];
myAnnotation.subtitle = [ objectForKey:@"Address"];
myAnnotation.icon = [ objectForKey:@"Icon"];
;
;
}
}
else { //Do nothing }
//And same with other categories....
//Update the ui dispatch_async(dispatch_get_main_queue(), ^{
}); }
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您正在从非 UI 更新 UI - 线程这将不起作用</p>
<p>您将不得不在 UIThreadblock 中调用更新您的 ui 的代码段,如下所示:</p>
<p>例如</p>
<pre><code>;
</code></pre>
<p>必须在 UI-Thread 中调用</p>
<pre><code> dispatch_async(dispatch_get_main_queue(), ^{
//Update UI if you have to
;
});
</code></pre>
<p>请注意,您必须在 main_queue 线程中调用所有 UI 更新</p>
<pre><code> dispatch_async(dispatch_get_main_queue(), ^{
//All UI updating code must come here
});
</code></pre></p>
<p style="font-size: 20px;">关于ios - 使用后台线程从 url 加载注释。在移动或缩放 mapView 之前,引脚不显示,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10862914/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10862914/
</a>
</p>
页:
[1]