2015-05-08 7 views
7

Ich habe eine UITableViewCell, die eine Kartenansicht als Subview hat. Eine benutzerdefinierte Klasse erstellt, die alle Aktionen wie das Hinzufügen von Anmerkungen, Delegaten usw. verarbeitet und sie als CustomeMap.swift bezeichnet.Benutzerdefinierte Kartenansicht Absturz in InitWithCoder in Swift

Nachdem ich Klassenname der Kartenansicht auf CustomeMap in Zelle geändert Xib, stürzt App einige Male bei initWithCoder Methode von CustomeMap, weil ich diese Methode nicht implementiert haben. Später habe ich die Methode wie folgt hinzugefügt:

aber immer noch das gleiche Problem.

Crashlog

Crashed: com.apple.main-thread 
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000001 


    Thread : Crashed: com.apple.main-thread 
0 libGPUSupportMercury.dylib  0x2b7228fe gpus_ReturnNotPermittedKillClient 
1 libGPUSupportMercury.dylib  0x2b7233cb gpusSubmitDataBuffers 
2 libGPUSupportMercury.dylib  0x2b723249 gldCreateContext 
3 GLEngine      0x2717191b gliCreateContextWithShared 
4 OpenGLES      0x2724dab3 -[EAGLContext initWithAPI:properties:] + 406 
5 OpenGLES      0x2724d86f -[EAGLContext initWithAPI:sharedWithCompute:] + 142 
6 VectorKit      0x2fc2d58b ggl::OESContext::OESContext(ggl::GLDevice*, std::__1::shared_ptr<ggl::OESSharegroup>) + 530 
7 VectorKit      0x2fc2663f ggl::GLDevice::createRenderer() + 110 
8 VectorKit      0x2fb46c0f -[MDDisplayLayer _createGLLayer] + 166 
9 VectorKit      0x2fb469af -[MDDisplayLayer init] + 70 
10 VectorKit      0x2f8763b7 -[VKMapView initWithGlobe:shouldRasterize:inBackground:] + 486 
11 MapKit       0x25f4937f -[MKBasicMapView initWithFrame:andGlobe:shouldRasterize:] + 362 
12 MapKit       0x25f7b14b -[MKMapView _commonInitFromIB:gestureRecognizerHostView:showsAttribution:] + 982 
13 MapKit       0x25f7bc4d -[MKMapView initWithCoder:] + 128 
14 AppName      0x000ce410 @objc AppName.CustomeMap.init (AppName.CustomeMap.Type)(coder : ObjectiveC.NSCoder) -> AppName.CustomeMap (CustomeMap.swift) 
15 UIKit       0x280f6611 -[UIClassSwapper initWithCoder:] + 192 
16 UIKit       0x281bd6ef UINibDecoderDecodeObjectForValue + 850 
17 UIKit       0x281bd38f -[UINibDecoder decodeObjectForKey:] + 334 
18 UIKit       0x280f6253 -[UIRuntimeConnection initWithCoder:] + 150 
19 UIKit       0x281bd6ef UINibDecoderDecodeObjectForValue + 850 
20 UIKit       0x281bd645 UINibDecoderDecodeObjectForValue + 680 
21 UIKit       0x281bd38f -[UINibDecoder decodeObjectForKey:] + 334 
22 UIKit       0x280f593f -[UINib instantiateWithOwner:options:] + 958 
23 UIKit       0x28014077 -[UIViewController _loadViewFromNibNamed:bundle:] + 238 
24 UIKit       0x27e52e99 -[UIViewController loadView] + 92 
25 UIKit       0x27d370ed -[UIViewController loadViewIfRequired] + 68 
26 UIKit       0x27de0ed5 -[UINavigationController _layoutViewController:] + 32 
27 UIKit       0x27de0dfd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 228 
28 UIKit       0x27de0393 -[UINavigationController _startTransition:fromViewController:toViewController:] + 74 
29 UIKit       0x27de00c3 -[UINavigationController _startDeferredTransitionIfNeeded:] + 578 
30 UIKit       0x27ddfe2d -[UINavigationController __viewWillLayoutSubviews] + 44 
31 UIKit       0x27ddfdc1 -[UILayoutContainerView layoutSubviews] + 184 
32 UIKit       0x27d347ff -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 514 
33 QuartzCore      0x2775a835 -[CALayer layoutSublayers] + 136 
34 QuartzCore      0x2775620d CA::Layer::layout_if_needed(CA::Transaction*) + 360 
35 QuartzCore      0x27756095 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16 
36 QuartzCore      0x27755a71 CA::Context::commit_transaction(CA::Transaction*) + 224 
37 QuartzCore      0x27755875 CA::Transaction::commit() + 324 
38 UIKit       0x27d2cc91 _afterCACommitHandler + 132 
39 CoreFoundation     0x247e0ffd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20 
40 CoreFoundation     0x247de6bb __CFRunLoopDoObservers + 278 
41 CoreFoundation     0x247deac3 __CFRunLoopRun + 914 
42 CoreFoundation     0x2472c3b1 CFRunLoopRunSpecific + 476 
43 CoreFoundation     0x2472c1c3 CFRunLoopRunInMode + 106 
44 GraphicsServices    0x2bd59201 GSEventRunModal + 136 
45 UIKit       0x27d9643d UIApplicationMain + 1440 
46 AppName      0x000c1d68 main (AppDelegate.swift:17) 

Subclassing Konzept entfernt, erstellt nur eine Ansicht und hinzugefügt MKMapView als Unteransicht. aber jetzt sehe ich folgende Absturz

Crashlog

Thread : Crashed: com.apple.main-thread 
0 libGPUSupportMercury.dylib  0x2fc468fe gpus_ReturnNotPermittedKillClient 
1 libGPUSupportMercury.dylib  0x2fc473cb gpusSubmitDataBuffers 
2 libGPUSupportMercury.dylib  0x2fc47249 gldCreateContext 
3 GLEngine      0x2b87393b gliCreateContextWithShared 
4 OpenGLES      0x2b94fab3 -[EAGLContext initWithAPI:properties:] + 406 
5 OpenGLES      0x2b94f86f -[EAGLContext initWithAPI:sharedWithCompute:] + 142 
6 VectorKit      0x33ffde8b ggl::OESContext::OESContext(ggl::GLDevice*, std::__1::shared_ptr<ggl::OESSharegroup>) + 530 
7 VectorKit      0x33ff6e77 ggl::GLDevice::createRenderer() + 110 
8 VectorKit      0x33f1399b -[MDDisplayLayer _createGLLayer] + 166 
9 VectorKit      0x33f1373b -[MDDisplayLayer init] + 70 
10 VectorKit      0x33c3eae3 -[VKMapView initWithGlobe:shouldRasterize:inBackground:] + 486 
11 MapKit       0x2a6586d7 -[MKBasicMapView initWithFrame:andGlobe:shouldRasterize:] + 362 
12 MapKit       0x2a68a67f -[MKMapView _commonInitFromIB:gestureRecognizerHostView:showsAttribution:] + 1018 
13 MapKit       0x2a676b83 -[MKMapView initWithFrame:] + 130 
14 UIKit       0x2c44df19 -[UIView init] + 44 
15 AppName      0x000f7598 @!objc ObjectiveC.MKMapView.init (ObjectiveC.MKMapView.Type)() -> ObjectiveC.MKMapView (CustomeMap.swift) 
16 AppName      0x000f4f1c ObjectiveC.MKMapView.__allocating_init (ObjectiveC.MKMapView.Type)() -> ObjectiveC.MKMapView (CustomeMap.swift) 
17 AppName      0x000ef614 AppName.CustomeMap.awakeFromNib (AppName.CustomeMap)() ->() (CustomeMap.swift:31) 
18 AppName      0x000f06ec @objc AppName.CustomeMap.awakeFromNib (AppName.CustomeMap)() ->() (CustomeMap.swift) 
19 UIKit       0x2c7ee561 -[UINib instantiateWithOwner:options:] + 1680 
20 UIKit       0x2c70d303 -[UIViewController _loadViewFromNibNamed:bundle:] + 238 
21 UIKit       0x2c54c805 -[UIViewController loadView] + 92 
22 UIKit       0x2c430af9 -[UIViewController loadViewIfRequired] + 68 
23 UIKit       0x2c4dab75 -[UINavigationController _layoutViewController:] + 32 
24 UIKit       0x2c4daa9d -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 228 
25 UIKit       0x2c4da033 -[UINavigationController _startTransition:fromViewController:toViewController:] + 74 
26 UIKit       0x2c4d9d63 -[UINavigationController _startDeferredTransitionIfNeeded:] + 578 
27 UIKit       0x2c4d9acd -[UINavigationController __viewWillLayoutSubviews] + 44 
28 UIKit       0x2c4d9a61 -[UILayoutContainerView layoutSubviews] + 184 
29 UIKit       0x2c42e24f -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 514 
30 QuartzCore      0x2be56a0d -[CALayer layoutSublayers] + 136 
31 QuartzCore      0x2be523e5 CA::Layer::layout_if_needed(CA::Transaction*) + 360 
32 QuartzCore      0x2be5226d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16 
33 QuartzCore      0x2be51c51 CA::Context::commit_transaction(CA::Transaction*) + 224 
34 QuartzCore      0x2be51a55 CA::Transaction::commit() + 324 
35 UIKit       0x2c4266e5 _afterCACommitHandler + 132 
36 CoreFoundation     0x28f34d95 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20 
37 CoreFoundation     0x28f32453 __CFRunLoopDoObservers + 278 
38 CoreFoundation     0x28f3285b __CFRunLoopRun + 914 
39 CoreFoundation     0x28e803c1 CFRunLoopRunSpecific + 476 
40 CoreFoundation     0x28e801d3 CFRunLoopRunInMode + 106 
41 GraphicsServices    0x302550a9 GSEventRunModal + 136 
42 UIKit       0x2c48ffa1 UIApplicationMain + 1440 
43 AppName      0x000eb500 main (AppDelegate.swift:21) 
44 libdyld.dylib     0x36fa6aaf start + 2 

jemand bitte helfen zu finden, was ich hier fehlt.

+0

können Sie Code von CustomeMap.swift posten? –

+1

Es ist schwer zu sagen, warum es aufgrund der von Ihnen bereitgestellten Informationen abstürzt. Eine Sache: Ein Objekt zu einem eigenen Delegaten zu machen, ist eine schlechte Idee. –

+0

Fügen Sie Ausnahme-Breakpoints hinzu, um das Problem einzugrenzen. In xCode gehen Sie zu "Debug" als "Breakpoints" als "Exception Breakpoints erstellen". Sobald Sie die Ursache Update-Frage kennen. –

Antwort

1

Es sieht so aus, als würde die Unterklasse mit den ursprünglichen Initialisierungsmethoden herumspielen. Die Dokumente für MKMapView sagen, dass Sie keine Unterklasse erstellen sollten, aber verwenden Sie den Delegaten für alles, was Sie benötigen.

Obwohl Sie die MKMapView-Klasse nicht selbst ableiten sollten, können Sie Informationen über das Verhalten der Kartenansicht erhalten, indem Sie ein Delegate-Objekt bereitstellen.

Ich schlage vor, Sie eine UIView Unterklasse benutzerdefinierte erstellen, die eine MKMapView enthält und fungiert als ihr Beauftragter. Dies ist der erste Schritt, den ich unternehmen würde, um das Problem zu lösen.

+0

aktualisierten meine Fragen mit neuen Änderungen @Jernej – naresh

+0

@naresh So wird der Absturz durch OpenGL-Aufrufe verursacht, während die App im Hintergrund ist (oder in diesen Zustand übergeht). Es scheint, als ob MKMapView diese Aufrufe verursacht, aber iOS wird jede App beenden, die dies versucht. Gibt es Übergänge von Hintergrund/Vordergrund? Zu welchem ​​Zeitpunkt tritt der Absturz genau auf? –

+0

Ich verwende keine OpenGL-Aufrufe, habe nur eine Tabellenansicht Zelle mit Xib erstellt, die diese CustomMap hat, ich habe eine Frage Können wir ein Objekt für MKMapView in watchFromNib erstellen, wenn ich mit @Jernej Ansatz gehe? – naresh