2017-03-06 62 views
0

我的組件MapView[email protected]在我的應用程序。在MapView中,我有一個可拖動的MapView.Marker。 問題是,有時當我拖動此標記應用程序突然崩潰與例外。是的,有時候這很奇怪。爲什麼在MapView.Marker拖動後應用程序崩潰?

Terminating app due to uncaught exception 'NSRangeException', reason:'Cannot remove an observer <AIRMapManager 0x6080000096b0> for the key path "center" from <AIRMapMarker 0x7fdb4a68f4f0> because it is not registered as an observer.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010c9e0b2b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010b89b281 objc_exception_throw + 48 
    2 CoreFoundation      0x000000010ca49685 +[NSException raise:format:] + 197 
    3 Foundation       0x000000010b3b8a38 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 497 
    4 Foundation       0x000000010b3b87ec -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 84 
    5 mojazastavka_ios     0x000000010aed6949 -[AIRMapManager mapView:annotationView:didChangeDragState:fromOldState:] + 1321 
    6 MapKit        0x000000010e66dd9a -[MKMapView _annotationViewDragStateChanged:] + 440 
    7 CoreFoundation      0x000000010c97fc2c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 
    8 CoreFoundation      0x000000010c97fb29 _CFXRegistrationPost + 425 
    9 CoreFoundation      0x000000010c97f892 ___CFXNotificationPost_block_invoke + 50 
    10 CoreFoundation      0x000000010c943132 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826 
    11 CoreFoundation      0x000000010c942291 _CFXNotificationPost + 673 
    12 Foundation       0x000000010b367328 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66 
    13 MapKit        0x000000010e73f916 -[MKAnnotationView setDragState:animated:] + 224 
    14 MapKit        0x000000010e7ebb4f -[MKAnnotationContainerView _dropDraggingAnnotationViewAnimated:] + 276 
    15 MapKit        0x000000010e66b928 -[MKMapView _dropDraggingAnnotationView:] + 91 
    16 MapKit        0x000000010e66bbac -[MKMapView handleLongPress:] + 604 
    17 UIKit        0x000000010f553751 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57 
    18 UIKit        0x000000010f55b54f _UIGestureRecognizerSendTargetActions + 109 
    19 UIKit        0x000000010f558f03 _UIGestureRecognizerSendActions + 225 
    20 UIKit        0x000000010f5581c6 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 981 
    21 UIKit        0x000000010f544728 _UIGestureEnvironmentUpdate + 1219 
    22 UIKit        0x000000010f544219 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484 
    23 UIKit        0x000000010f5433e0 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274 
    24 UIKit        0x000000010f092baa -[UIWindow sendEvent:] + 4092 
    25 UIKit        0x000000010f03f274 -[UIApplication sendEvent:] + 352 
    26 UIKit        0x000000010f81efa8 __dispatchPreprocessedEventFromEventQueue + 2932 
    27 UIKit        0x000000010f816f74 __handleEventQueue + 1115 
    28 CoreFoundation      0x000000010c986c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    29 CoreFoundation      0x000000010c96c0af __CFRunLoopDoSources0 + 527 
    30 CoreFoundation      0x000000010c96b5df __CFRunLoopRun + 911 
    31 CoreFoundation      0x000000010c96aff6 CFRunLoopRunSpecific + 406 
    32 GraphicsServices     0x0000000112905979 GSEventRunModal + 62 
    33 UIKit        0x000000010f021bb1 UIApplicationMain + 159 
    34 mojazastavka_ios     0x000000010aecd67f main + 111 
    35 libdyld.dylib      0x00000001109fc66d start + 1 
    36 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

我真的不知道是什麼原因,代碼是根據官方的例子:

import React, {Component} from 'react'; 
import MapView from 'react-native-maps'; 
import MyCustomCallout from './MyCustomCallout'; 

export default class Map extends Component{ 

    constructor(props) { 
    super(props); 

    let marker = null; 
    } 

    render(){ 
     return (
      <MapView> 
       <MapView.Marker 
       draggable 
       onDragEnd={e => console.log(e.nativeEvent)} 
       coordinate={{ 
        latitude: this.props.latitude, 
        longitude: this.props.longitude 
       }} 
       ref={ref => this.marker = ref } 
       image={finishImg}> 
        <MyCustomCallout type={'FINISH'} descriptionText={this.props.destinationName} /> 
       </MapView.Marker> 
      </MapView> 
    ); 
    } 
} 

回答

0

由模擬器刪除應用程序,並改建工程解決。原創解決方案here