2015-05-08 25 views
7

Ho un UITableViewCell, che ha una vista mappa come sottoview. Creata una classe personalizzata che gestisce tutte le azioni come aggiungere annotazioni, delegati ecc. E denominarla come CustomeMap.swift.Visualizzazione mappa personalizzata che si interrompe in initWithCoder in swift

Dopo aver cambiato il nome della classe di vista della mappa per CustomeMap in cellulare Xib, applicazione va in crash a volte a initWithCoder metodo CustomeMap perché non ho implementato tale metodo. Più tardi ho aggiunto il metodo come segue:

import UIKit 
import MapKit 


protocol CustomeMapDelegate{ 
    func annotationClickEvent(info:NSDictionary?) 
} 

class CustomeMap: MKMapView,MKMapViewDelegate,CLLocationManagerDelegate { 

    var locationManager:CLLocationManager? 
    var delegate1:CustomeMapDelegate? 
    var tap:UITapGestureRecognizer? 

    required init(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    override func awakeFromNib() 
    { 
     if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedAlways { 
      self.showsUserLocation = true; 
     } 
     else 
     { 
      locationManager = CLLocationManager() 
      locationManager?.delegate = self; 
      if locationManager!.respondsToSelector("requestAlwaysAuthorization") 
      { 
       locationManager?.requestAlwaysAuthorization() 
      } 
     } 
     self.delegate = self 
     self.userInteractionEnabled = true 
     tap = UITapGestureRecognizer(target: self, action: "calloutAction:") 
    } 
    func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) 
    { 
     if(status == CLAuthorizationStatus.AuthorizedAlways) 
     { 
      self.showsUserLocation = true; 
     } 
    } 

    func skipTouch() 
    { 

    } 

    class func createAnnotationForDict(temp:NSDictionary)->MyPointAnnotation 
    { 
     var venue = temp.valueForKey("venue") as? NSDictionary 
     var lat = venue!.valueForKey("latitude") as! Double 
     var lon = venue!.valueForKey("longitude") as! Double 
     var venueName = venue!.valueForKey("name") as! String 
     var dealName = temp.valueForKey("title") as? String 

     var coord:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0, longitude: 0) 
     coord.latitude = lat 
     coord.longitude = lon 
     var point = MyPointAnnotation() 
     point.userInfo = temp 
     point.coordinate = coord 
     point.title = dealName 
     point.subtitle = venueName 
     return point 
    } 

    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! 
    { 
     if annotation is MKUserLocation { 
      return nil 
     } 

     let reuseId = "pin" 

     var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView 
     if pinView == nil { 
      pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
      pinView!.canShowCallout = true 
      pinView!.animatesDrop = true 
      pinView!.pinColor = .Red 

      var assImg = UIImageView(image: UIImage(named: "r_arrow_g")) 
      assImg.frame = CGRectMake(0, 0, 16, 16) 
      assImg.contentMode = UIViewContentMode.ScaleAspectFit 
      pinView!.rightCalloutAccessoryView = assImg 

     } 
     else { 
      pinView!.annotation = annotation 
     } 
     return pinView 
    } 
    func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) 
    { 
     if view.annotation.isKindOfClass(MKUserLocation){ return } 
     if let t1 = tap 
     { 

     } 
     else 
     { 
      tap = UITapGestureRecognizer(target: self, action: "calloutAction:") 
     } 
     view.addGestureRecognizer(tap!) 
    } 
    func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) 
    { 
     if view.annotation.isKindOfClass(MKUserLocation){ return } 
     view.removeGestureRecognizer(tap!) 
    } 
    func calloutAction(sender:UITapGestureRecognizer) 
    { 
     if(delegate1 != nil) 
     { 
      var view = sender.view as! MKAnnotationView 
      var ann = view.annotation as! MyPointAnnotation 
      delegate1!.annotationClickEvent(ann.userInfo) 
     } 
    } 

} 

ma ancora lo stesso problema.

crash log

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) 

Rimosso Subclassing concetto, appena creato un punto di vista e ha aggiunto MKMapView come sotto-vista. ma ora sto vedendo seguente incidente

crash log

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 

Qualcuno si prega di aiuto per trovare quello che mi manca qui.

+0

puoi pubblicare un codice di CustomeMap.swift? –

+1

È difficile dire perché si è verificato un arresto anomalo rispetto alle informazioni fornite. Una cosa: rendere un oggetto il proprio delegato è una cattiva idea. –

+0

Aggiungere punti di interruzione Eccezione per limitare il problema. In xCode, vai a "Debug" di "Breakpoint" di "Crea punti di interruzione delle eccezioni". Una volta che conosci la domanda di aggiornamento della causa. –

risposta

1

Sembra che la sottoclasse stia scherzando con i metodi di inizializzazione originali. I documenti per MKMapView dicono che non dovresti sottoclasse, ma usa il delegato per tutto ciò che ti serve.

Sebbene non sia necessario creare una sottoclasse della classe MKMapView, è possibile ottenere informazioni sul comportamento della visualizzazione della mappa fornendo un oggetto delegato.

Vi suggerisco di creare una sottoclasse personalizzata UIView, che contiene un MKMapView e agisce come suo delegato. Questo è il primo passo che farei per cercare di risolvere questo problema.

+0

ha aggiornato le mie domande con le nuove modifiche @Jernej – naresh

+0

@naresh Quindi, l'arresto anomalo è causato dalle chiamate OpenGL effettuate mentre l'app è in background (o passa a quello stato). Sembra che MKMapView stia causando questa chiamata, ma iOS ucciderà qualsiasi app che tenti di farlo. Ci sono delle transizioni da sfondo/primo piano coinvolti? A che punto si verifica esattamente l'incidente? –

+0

Non sto usando nessuna chiamata OpenGL, ho appena creato una cella tableview usando xib, che sta avendo questa CustomMap, ho una domanda. Possiamo creare un oggetto per MKMapView in awakeFromNib se vado con l'approccio @Jernej? – naresh