EXC_BAD_ACCESS当我提出内部市​​场的视图控制器时

时间:2015-07-06 20:06:44

标签: ios xcode mapkit exc-bad-access

我在使用Mapkit内部呈现视图控制器时遇到问题。我第一次提出它时工作正常,但是当我再次出现它时会抛出一个EXC_BAD_ACCESS ERROR。编程语言很快。任何帮助表示赞赏。 Xcode 6.4。 iOS 8

ViewController.swift

@IBAction func OnClickTallaCamiseta(sender: AnyObject)
{
    txtTallaCamiseta.endEditing(true);
    //ocultarTallaCamiseta();

    self.performSegueWithIdentifier("mostrarMapa", sender: self)
}

func hecho(controller: MapaController, ciudad: String, departamento: String, pais: String)
{
    navigationController?.setNavigationBarHidden(true, animated: true);

    ciudadSeleccionada = ciudad;
    departamentoSeleccionado = departamento;
    paisSeleccionado = pais;

    var label:String = "";

    if(ciudadSeleccionada != "NO_DATA")
    {
        label += ciudadSeleccionada;
    }

    if(departamentoSeleccionado != "NO_DATA")
    {
        label += ", " + departamentoSeleccionado;
    }

    if(paisSeleccionado != "NO_DATA")
    {
        label += ", " + paisSeleccionado;
    }

    lblCiudadEres.text = label;

    self.navigationController?.popViewControllerAnimated(true);
}

func terminado(controller: MapaController)
{
    println("terminado");
    navigationController?.setNavigationBarHidden(true, animated: true);
    self.navigationController?.popViewControllerAnimated(true);
}

MapaController.swift

import Foundation
import UIKit
import GoogleMaps
import MapKit
import CoreLocation

protocol MapaControllerDelegate
{
func terminado(controller:MapaController);
func hecho(controller:MapaController, ciudad:String,     departamento:String, pais:String);
}

class MapaController : UIViewController, UITableViewDataSource, UITableViewDelegate,
GPSDelegate, MKMapViewDelegate
{
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var btnDone: UIBarButtonItem!
@IBOutlet weak var txtSearch: UITextField!

var locationManager:CLLocationManager = CLLocationManager();
var camera:GMSCameraPosition? = nil;
var aqui:CLLocationCoordinate2D? = nil;
var ne:CLLocationCoordinate2D? = nil;
var sw:CLLocationCoordinate2D? = nil;
var bounds:GMSCoordinateBounds? = nil;
var placesClient:GMSPlacesClient = GMSPlacesClient();
var data:[GMSAutocompletePrediction] = [GMSAutocompletePrediction]();
var ciudad = "";
var departamento = "";
var pais = "";
var delegate:MapaControllerDelegate? = nil;
var gps = GPSLocation;

let filter = GMSAutocompleteFilter();

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

override func viewDidLoad()
{
    super.viewDidLoad();

    placesClient = GMSPlacesClient();
    filter.type = GMSPlacesAutocompleteTypeFilter.Geocode;

    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell");
    self.tableView.hidden = true;

    self.btnDone.enabled = false;

    navigationController?.setNavigationBarHidden(false, animated: true);


    //setMarkerAndMoveCamera(gps.lat, longitud: gps.long);

    gps.gpsDelegate = self;
    println("TERMINA");    }

@IBAction func OnTextChanged(sender: AnyObject)
{
    if(!txtSearch.text.isEmpty)
    {
        //println("Searching for '\(self.txtSearch.text)'");

        placesClient.autocompleteQuery(self.txtSearch.text,
            bounds: bounds,
            filter: filter,
            callback: { (results, error) -> Void in
                if error != nil
                {
                    println("Autocomplete error \(error) for query '\(self.txtSearch.text)'")
                    return
                }

                //println("Populating results for query '\(self.txtSearch.text)'");
                self.data = [GMSAutocompletePrediction]();

                for result in results!
                {
                    if let result = result as? GMSAutocompletePrediction
                    {
                        self.data.append(result)
                    }
                }

                self.tableView.reloadData();
                self.tableView.hidden = false;

                if(!self.btnDone.enabled)
                {
                    self.btnDone.enabled = true;
                }
        });
    }
    else
    {
        self.data = [GMSAutocompletePrediction]()
        self.tableView.reloadData()
        self.tableView.hidden = true;
    }
}

func CoordUpdated(latitud: Double, longitud: Double)
{
    moverCamara(latitud, longitud: longitud);

    aqui = CLLocationCoordinate2DMake(latitud, longitud);
    ne = CLLocationCoordinate2DMake(aqui!.latitude + 1, aqui!.longitude + 1);
    sw = CLLocationCoordinate2DMake(aqui!.latitude - 1, aqui!.longitude - 1);
    bounds = GMSCoordinateBounds(coordinate: ne!, coordinate: sw!);
}

func CoordenadasGuardadas(exito: Bool){}

func VisitaMarcada(exito: Bool){}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return self.data.count;
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell;

    cell.textLabel?.text = self.data[indexPath.row].attributedFullText.string;

    return cell;
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    txtSearch.text = self.data[indexPath.row].attributedFullText.string;
    txtSearch.endEditing(true);

    var placeId:String = self.data[indexPath.row].placeID;
    tableView.hidden = true;

    placesClient.lookUpPlaceID(placeId,
        callback: {(place, error) -> Void in
        if error != nil
        {
            println("lookup place id query error: \(error!.localizedDescription)")
            return
        }

        if place != nil
        {
            var coordenada:CLLocationCoordinate2D = place!.coordinate;
            var lat = coordenada.latitude;
            var long = coordenada.longitude;

            self.setMarkerAndMoveCamera(lat, longitud: long);

            var array = split(self.data[indexPath.row].attributedFullText.string) {$0 == ","};

            if(array.count == 3)
            {
                self.ciudad = array[0];
                self.departamento = array[1];
                self.pais = array[2];
            }
            else if(array.count == 2)
            {
                self.ciudad = array[0];
                self.departamento = "NO_DATA";
                self.pais = array[1];
            }
            else
            {
                self.ciudad = array[0];
                self.departamento = "NO_DATA";
                self.pais = "NO_DATA";
            }
        }
        else
        {
            println("No place details for \(placeId)")
        }
    });
}

func moverCamara(latitud:Double, longitud:Double)
{
    /*let location = CLLocationCoordinate2D(latitude: latitud, longitude: longitud)
    let span = MKCoordinateSpanMake(0.05, 0.05)
    let region = MKCoordinateRegion(center: location, span: span)

    mapa.setRegion(region, animated: true)*/
}

func setMarkerAndMoveCamera(latitud:Double, longitud:Double)
{
    /*let location = CLLocationCoordinate2D(latitude: latitud, longitude: longitud)
    let span = MKCoordinateSpanMake(0.05, 0.05)
    let region = MKCoordinateRegion(center: location, span: span)

    mapa.setRegion(region, animated: true)

    let annotationsToRemove = self.mapa.annotations.filter { $0 !== self.mapa.userLocation }
    mapa.removeAnnotations( annotationsToRemove )

    let annotation = MKPointAnnotation()
    annotation.coordinate = location;
    annotation.title = NSLocalizedString("label_ciudad_encontrada",comment:"label_ciudad_encontrada");

    mapa.addAnnotation(annotation);*/
}

@IBAction func OnDone(sender: AnyObject)
{
    delegate?.hecho(self, ciudad: ciudad, departamento: departamento, pais: pais);
}

@IBAction func OnCancel(sender: AnyObject)
{
    delegate?.terminado(self);
}

override func viewWillDisappear(animated:Bool)
{
    self.tableView.delegate = nil;
}
@IBAction func onCancelar(sender: AnyObject)
{
    delegate?.terminado(self);
}
}

1 个答案:

答案 0 :(得分:0)

你需要识别单元格,在这种情况下使用" cell"。

  1. 选择您的tableview,然后在属性检查器中选择原型单元格为1。

  2. 展开表视图,然后选择viewCell

  3. 在选项中选项"标识符" put" cell"。