swift - 崩溃 : Can only call -[PFObject init] on subclasses conforming to PFSubclassing

标签 swift uitableview swift2 segue

您好,我正在学习 Swift,我正在尝试将 Parse 实现到我的应用程序中。所以我有一个 MapView,它有一些注释。这些注释是从存储在 Parse 数据库中的坐标绘制的。 Parse 中的每个坐标元组都有其他详细信息,如 FirstName LastName 等。现在,一旦用户单击 mapView 中存在的 DETAILS 按钮。它将用户带到一个 TableView Controller ,用户可以在其中看到与在 mapView 中可见的坐标有关的所有详细信息。到现在为止一切正常。所以如果我在 map View 中有 4 个注释。然后通过单击 DETAILS,我被重定向到 TableView Controller ,在那里我可以看到与 mapView 中存在的所有坐标/注释相关的详细信息。现在我想要一个用户可以点击 TableView Controller 单元格的功能,我可以将数据传递给与该特定单元格相关的另一个 View 。因此,如果在 TableView Controller 中,用户单击属于 map View 上显示的注释之一的第 4 个单元格。我希望将第 4 个单元格详细信息传递给另一个 View Controller 。

map View (带有多个注释)-> tableview Controller (带有多个单元格)-> View Controller (与用户点击的单元格相关)。

问题:只要我单击 TableView Controller 中的任何单元格,以便我可以在另一个 View Controller 中看到该单元格的详细信息,我的应用程序就会崩溃,我会看到错误

2015-11-30 21:38:42.998 LifeLine[53788:6661072] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can only call -[PFObject init] on subclasses conforming to PFSubclassing.'

我在 TableView Controller 中放置了断点 AT​​ PREPAREFORSEGUE METHOD。但即使在 prepareforsegue 方法断点命中之前,我的应用程序已经崩溃了。所以崩溃发生在我点击单元格和在 prepareforsegue 上设置断点之间。

我的 map View Controller :

import UIKit
import MapKit
import MessageUI

class MultipleAnnotationViewController: UIViewController, MKMapViewDelegate, MFMailComposeViewControllerDelegate
{
    var arrayOfPFObject: [PFObject] = [PFObject]()
    var lat_ :Double = 0
    var long_ :Double = 0
    @IBOutlet weak var dispAnnotation: MKMapView!
    let currentUser = PFUser.currentUser()
    var pinAnnotationView:MKPinAnnotationView!


    override func viewDidLoad()
    {
        super.viewDidLoad()
        dispAnnotation.delegate = self
        for coordinateItem in arrayOfPFObject
        {
            let pointAnnotation = MKPointAnnotation()
            self.lat_ = coordinateItem["Latitude"] as! Double
            self.long_ = coordinateItem["Longitude"] as! Double
            pointAnnotation.coordinate = CLLocationCoordinate2D(latitude:  self.lat_, longitude: self.long_)
            dispAnnotation.addAnnotation(pointAnnotation)

            pointAnnotation.title =  String(coordinateItem["FirstName"]) + "  " + String(coordinateItem["LastName"])



            let miles = 10.0
            let scalingFactor =  abs(( cos ( 2*M_PI*pointAnnotation.coordinate.latitude/360.0  ) ) )
            var span = MKCoordinateSpan(latitudeDelta: 0, longitudeDelta: 0)
            span.latitudeDelta = miles/69.0
            span.longitudeDelta = miles/(scalingFactor * 69.0)
            let region = MKCoordinateRegionMake(pointAnnotation.coordinate, span)
            [ self.dispAnnotation.setRegion(region, animated: true)]
        }
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
    {
        if segue.identifier == "TableView"
        {
            let controller = segue.destinationViewController as! TableViewController

            controller.arrayOfPFObject = arrayOfPFObject
        }
        if segue.identifier == "TableView2"
        {
            let controller = segue.destinationViewController as! ChecklistViewController

            controller.arrayOfPFObject = arrayOfPFObject
        }

    }


    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
    {
        guard !(annotation is MKUserLocation)
            else
        {
            return nil }
        let identifier = "com.domain.app.something"
        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? MKPinAnnotationView
        if annotationView == nil
        {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView?.pinTintColor = UIColor.redColor()
            annotationView?.canShowCallout = true
        }
        else
        {
            annotationView?.annotation = annotation
        }
        return annotationView
    }
}

我的 TableViewController:

import UIKit

class ChecklistViewController: UITableViewController
{

    override func viewDidLoad() {
        super.viewDidLoad()

    }

 var arrayOfPFObject: [PFObject] = [PFObject]()

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        return arrayOfPFObject.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier(
            "ChecklistItem", forIndexPath: indexPath)
        let label = cell.viewWithTag(1000) as! UILabel
        print(arrayOfPFObject.count)
            print(indexPath.row)
            let coordinateItem = arrayOfPFObject[indexPath.row]

            label.text = String(coordinateItem["Address"])
        return cell

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
    {
 if segue.identifier == "call"
  {
  let controller = segue.destinationViewController as! CallEmailViewController
if let indexPath = tableView.indexPathForCell( sender as! UITableViewCell)
    {
        controller.itemToEdit = arrayOfPFObject[indexPath.row]
          }

 }

   }  
}

我的 View Controller ,我想在其中显示所点击单元格的详细信息。

import UIKit
import CoreLocation
import MapKit

class CallEmailViewController: UITableViewController
{
    var itemToEdit: PFObject = PFObject()

    override func viewDidLoad()
    {
        super.viewDidLoad()
        mail()  //print(arrayOfPFObject.count)

    }

    func mail()
    {
        print("")
    }
}

下面是表格 View 图像。只要我点击任何表格 View ,我就会收到错误消息。

enter image description here

最佳答案

将 var itemToEdit: PFObject = PFObject() 更改为

var itemToEdit: PFObject?

关于swift - 崩溃 : Can only call -[PFObject init] on subclasses conforming to PFSubclassing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34012011/

相关文章:

swift - 密码被缓存在某处,需要清除它

ios - 选择和取消选择UITableView行

objective-c - 动态大小的 UITableViewCells

ios - 文本字段 shouldChangeCharactersInRange 未调用

ios - 在函数外更改 var 的值

ios - 快速的白色背景,从圆形的图像

swift - 在 swift 中使用单个函数/方法将多个 Sprite 节点添加到场景中

ios - 我如何找到 UITableview 滚动差异 - swift

ios - SpriteKitPhysicsBody非矩形碰撞

macos - 如何实时检查 NSTextField - Swift OS X