Ios MKMapView必须在主线程上初始化
我是iphone新手,使用Ios MKMapView必须在主线程上初始化,ios,cocoa-touch,mkmapview,Ios,Cocoa Touch,Mkmapview,我是iphone新手,使用MKMapView在我的应用程序中加载谷歌地图。但它引发了一个异常“MKMapView必须在主线程上初始化”。那么我应该在哪里初始化我的MKMapView对象呢。我正在viewDidLoad()中初始化 提前感谢….它没有在主线程上创建的原因是两个选项之一 创建它的视图位于其中一个后台线程上 您正在调用performSelectorInBackground:来创建视图 要在主线程上执行函数,请调用performselectornmainthread: 离题:如果函数需要
MKMapView
在我的应用程序中加载谷歌地图。但它引发了一个异常“MKMapView必须在主线程上初始化”。那么我应该在哪里初始化我的MKMapView
对象呢。我正在viewDidLoad()
中初始化
提前感谢….它没有在主线程上创建的原因是两个选项之一
performSelectorInBackground:
来创建视图performselectornmainthread:
离题:如果函数需要超过1个参数,请将其更改为NSDictionary,并将所有设置加载到Dictionary中,然后将其传入
NSDictionary *params = ...... //load your parameters into here
[myMapView performSelectorOnMainThread:@selector(initMap:)
withObject:params
waitUntilDone:YES];
同时阅读以下内容,为了更好地了解iOS中使用Swift 3的多线程处理,以下内容将确保您的函数在主线程上运行。 OperationQueue.main.addOperation{“您的segue或函数调用”}我收到了这个错误: MKMapView必须在主线程上初始化 当我试图以这种方式更改自定义
UITableViewCell
的内容时:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[myIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
The UITableviewCell in the corresponding indexpath contained a MKMapView that I tried to change its region.
myTabelViewCell *cell = [self.tableView cellForRowAtIndexPath:myIndexPath];
[cell setContentWithLatitude:currentLatitude longitude:currentLongitude];
使用上述代码而不是
[self.tableView reloadData]
只刷新一个单元格。您确实应该提供更多详细信息…我在viewDidLoad中使用以下代码,此视图由另一个视图调用mapView=[[MKMapView alloc]initWithFrame:cRectMake(0,0780920)];mapView.delegate=self;[self.view addSubview:mapView];[NSThread detachNewThreadSelector:@selector(displayMyMap)to target:self with object:nil];通过这样做,您正在创建一个新线程,请尝试更改为performSelectorOnMainThread,而不是DetachNewThreadSelectorTanks,以获得您的建议,但我仍然面临相同的问题欢迎您这样做。请用反勾号包装代码,使其显示为代码。