ios - MKMapView 必须在主线程上初始化
<p><p>我是 iphone 新手,使用 <code>MKMapView</code> 在我的应用程序中加载谷歌地图。但它抛出异常“MKMapView 必须在主线程上初始化。”。那么我应该在哪里初始化我的 <code>MKMapView</code> 对象。我正在 <code>viewDidLoad()</code> 中进行初始化。</p>
<p>提前致谢.....</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>它没有在主线程上创建的原因是 2 个选项之一</p>
<ol>
<li>创建它的 View 位于其中一个后台线程上</li>
<li>您正在调用 <code>performSelectorInBackground:</code> 来创建您的 View </li>
</ol>
<p>在主线程调用<code>performSelectorOnMainThread:</code></p>
<p>题外话:如果函数需要超过 1 个参数,请将其更改为 NSDictionary 并将所有设置加载到 Dictionary 中并将其传递给 eg</p>
<pre><code>NSDictionary *params = ...... //load your parameters into here
[myMapView performSelectorOnMainThread:@selector(initMap:)
withObject:params
waitUntilDone:YES];
</code></pre>
<p>另请阅读以下内容 <a href="http://www.google.com.au/url?sa=t&rct=j&q=forcing%20a%20call%20on%20the%20main%20thread%20iOS&source=web&cd=3&ved=0CC0QFjAC&url=http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html&ei=5EkMT_r3GIiaiQeEop36BQ&usg=AFQjCNFXoxOJXag9JgBwIeIL7BYeGExjfQ&cad=rja" rel="noreferrer noopener nofollow">First</a>和 <a href="http://www.google.com.au/url?sa=t&rct=j&q=forcing%20a%20call%20on%20the%20main%20thread%20iOS&source=web&cd=4&ved=0CDUQFjAD&url=http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html&ei=5EkMT_r3GIiaiQeEop36BQ&usg=AFQjCNE17Vky3OsDv6jcESIVf1Hu6qB8aw&cad=rja" rel="noreferrer noopener nofollow">Second</a>更好地理解 iOS 中的多线程</p></p>
<p style="font-size: 20px;">关于ios - MKMapView 必须在主线程上初始化,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8804725/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8804725/
</a>
</p>
页:
[1]