2012-12-23 38 views
0

因此,我正在跟随Ray Wenderlich的Mapkit教程发现here。我被卡在应该用plotCrimePositions方法在地图上绘制犯罪的部分。使用调试器,我已将其缩小到创建NSDictionary* root的位置,但似乎找不到该错误。任何帮助将不胜感激。 Here is a gist with relevant files.在Ray Wenderlich的Mapkit教程中使用SIGABRT

谢谢!

编辑:这里是我的控制台日志:

2012-12-23 16:31:52.925 MapTutorial[8993:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil' 
*** First throw call stack: 
(0x1850012 0x1645e7e 0x184fdeb 0x117a817 0x34697 0x35153 0x1659705 0x590920 0x7ccb24 0x1659705 0x590920 0x5908b8 0x651671 0x651bcf 0x650d38 0x5c033f 0x5c0552 0x59e3aa 0x58fcf8 0x223bdf9 0x223bad0 0x17c5bf5 0x17c5962 0x17f6bb6 0x17f5f44 0x17f5e1b 0x223a7e3 0x223a668 0x58d65c 0x341cd 0x2945) 
libc++abi.dylib: terminate called throwing an exception 
+1

当然,你正在获得一个SIGABRT,但你也应该在控制台中获得堆栈跟踪和更有用的错误。那些是什么? – CodaFi

+0

在上面添加它。谢谢! – ohayon

+0

我很确定它来自'root'因为'refreshData'方法中'responseData'为零的事实。 – ohayon

回答

1

你的问题是在这里:

- (IBAction)refreshTapped:(id)sender{ 
    //... 
    [request startAsynchronous]; //Start the request 
    [self plotCrimePositions:request.responseData]; //Assume there's data, 
    //despite the request not even have been given a chance to start 
} 

因为你认为你的request将同步执行,那么得到的是plotCrimePositions:当它结束,你认为请求得到的数据是非零(显然不是这样),这导致MapKit翻转。如果您将[self plotCrimePositions:request.responseData];移到您指定的完成处理程序的范围内,它应该像魅力一样工作。异步请求是异步的,意味着它们立即返回,这就是为什么完成块是天赐之物。

+0

你真棒。谢谢。 – ohayon