为什么我无法在前一个视图控制器上查看结构值
我对 Objective-C(以及 C 本身)还很陌生,所以这可能真的很容易,但我有点卡住了。
我有一个视图控制器,需要用户的一些输入,我有一个表视图,其中有一行用于纬度和经度值。当用户点击该行时,会将他们带到一个带有地图视图的新视图控制器。
我有一个标记供他们拖动并挑选出他们的位置:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
在这种方法中,我想用新坐标更新以前的视图控制器。
它有一个属性:
CLLocationCoordinate2D destinationCoordinates;
我已将其设置为非原子、分配和合成
我的代码执行此操作:
NSArray *allControllers = self.navigationController.viewControllers;
EnterDetailsViewController *parent = [allControllers objectAtIndex:([allControllers count] -2)];
if ([parent isKindOfClass:[EnterDetailsViewController class]])
{
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = annotation.coordinate.latitude;
theCoordinate.longitude = annotation.coordinate.longitude;
parent.destinationCoordinates = theCoordinate;
NSLog(@"Set coord to %@ - %@",
parent.destinationCoordinates.latitude,
parent.destinationCoordinates.latitude);
但是 NSLog
总是因 EXC_BAD_ACCESS
崩溃 - 这是为什么?我在这里误解了什么核心概念?
I'm pretty new to Objective-C (and C itself) so this is probably really easy, but I'm a bit stuck.
I've got a view controller that requires some input from the user, I have a table view that has a row for a latitude and longitude value. When the user taps that row, it takes them to a new view controller with a map view on it.
I've got a marker for them to drag and pick out their location:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
In this method I want to update the previous view controller with the new coordinates.
It has a property:
CLLocationCoordinate2D destinationCoordinates;
which I've set as nonatomic, assign and synthesized
My code does this:
NSArray *allControllers = self.navigationController.viewControllers;
EnterDetailsViewController *parent = [allControllers objectAtIndex:([allControllers count] -2)];
if ([parent isKindOfClass:[EnterDetailsViewController class]])
{
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = annotation.coordinate.latitude;
theCoordinate.longitude = annotation.coordinate.longitude;
parent.destinationCoordinates = theCoordinate;
NSLog(@"Set coord to %@ - %@",
parent.destinationCoordinates.latitude,
parent.destinationCoordinates.latitude);
But the NSLog
always crashes with an EXC_BAD_ACCESS
- why is this? What core concept am I misunderstanding here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CLLocationCooperative2D
的定义是:您使用 %@ 来打印对象,请尝试改为:
注意
CLLocationDegrees
的类型为 double:The definition of
CLLocationCoordinate2D
is:Your using %@ to print an object, try instead:
Note that
CLLocationDegrees
is of type double: