连接到原型单元时无法使单元错误出列

时间:2016-09-10 08:32:41

标签: ios swift uitableview

我被困在我认为简单的任务上。 我有UITableView设置为Prototype Cell。

我在" case"。

中添加了一些特定用途的单元格

我收到错误"无法使标识符为TankStartCell的单元格出列 - 必须为标识符注册一个nib或类,或者在故事板中连接原型单元格"但是,场景设置为原型单元格。

有问题的小组确实有" StartTankCell"在标识符中。

位置单元格正常工作。

我尝试过添加:     self.tableView.registerClass(UITableViewCell.self,forCellReuseIdentifier:" StartTankCell") 但没有去。 我已经尝试将课程设为UIViewController并添加UITableViewDelegate,但没有去。

private let NumberOfSections: Int               = 6
private let NumberOfRowsInSection0: Int         = 1
private let NumberOfRowsInSection1: Int         = 4
private let NumberOfRowsInSection2: Int         = 5
private let NumberOfRowsInSection3: Int         = 6
private let NumberOfRowsInSection4: Int         = 8
private let NumberOfRowsInSection5: Int         = 1



//  Section 0 Cells
private let DiveLocationIndex: NSIndexPath              = NSIndexPath(forRow: 0, inSection: 0)

//  Section 1 Cells
private let DiveStartingPressureIndex: NSIndexPath      = NSIndexPath(forRow: 0, inSection: 1)
private let DiveEndingPressureIndex: NSIndexPath        = NSIndexPath(forRow: 1, inSection: 1)
private let DiveTempPickerIndexAir: NSIndexPath         = NSIndexPath(forRow: 2, inSection: 1)
private let DiveTempPickerIndexWater: NSIndexPath       = NSIndexPath(forRow: 3, inSection: 1)

//  Section 2 Cells
private let DiveWaterIndex: NSIndexPath                 = NSIndexPath(forRow: 0, inSection: 2)
private let DiveWeatherIndex: NSIndexPath               = NSIndexPath(forRow: 1, inSection: 2)
private let DiveSurfaceIndex: NSIndexPath               = NSIndexPath(forRow: 2, inSection: 2)
private let DiveCurrentsIndex: NSIndexPath              = NSIndexPath(forRow: 3, inSection: 2)
private let DiveVisibilityIndex: NSIndexPath            = NSIndexPath(forRow: 4, inSection: 2)

//  Section 3 Cells
private let DiveEntryTypeIndex: NSIndexPath             = NSIndexPath(forRow: 0, inSection: 3)
private let DiveWeightIndex: NSIndexPath                = NSIndexPath(forRow: 1, inSection: 3)
private let DiveDiveSuitIndex: NSIndexPath              = NSIndexPath(forRow: 2, inSection: 3)
private let DiveCircuitIndex: NSIndexPath               = NSIndexPath(forRow: 3, inSection: 3)
private let DiveAirTypeIndex: NSIndexPath               = NSIndexPath(forRow: 4, inSection: 3)
private let DiveDiveTypeIndex: NSIndexPath              = NSIndexPath(forRow: 5, inSection: 3)


// Section 4 Cells
private let DiveMasterTitleIndex: NSIndexPath           = NSIndexPath(forRow: 0, inSection: 4)
private let DiveMasterIndex: NSIndexPath                = NSIndexPath(forRow: 1, inSection: 4)
private let DiveCenterTitleIndex: NSIndexPath           = NSIndexPath(forRow: 2, inSection: 4)
private let DiveCenterIndex: NSIndexPath                = NSIndexPath(forRow: 3, inSection: 4)
private let DiveBoatTitleIndex: NSIndexPath             = NSIndexPath(forRow: 4, inSection: 4)
private let DiveBoatIndex: NSIndexPath                  = NSIndexPath(forRow: 5, inSection: 4)
private let DiveTripTitleIndex: NSIndexPath             = NSIndexPath(forRow: 6, inSection: 4)
private let DiveTripIndex: NSIndexPath                  = NSIndexPath(forRow: 7, inSection: 4)



override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

    var cell: UITableViewCell!

    switch indexPath
    {

    // Section 0
    case DiveLocationIndex:
        cell = tableView.dequeueReusableCellWithIdentifier(Resource.LocationCell)
        cell.textLabel!.text = "Location".localized
        cell.detailTextLabel!.text = String(format: "%f, %f", self.latitude, self.longitude)




    // Section 1
    case DiveStartingPressureIndex:
        let cell : DiveStartTankPressureTableViewCell = tableView.dequeueReusableCellWithIdentifier("TankStartCell", forIndexPath: indexPath) as! DiveStartTankPressureTableViewCell

        cell.lbl_Start_Pressure.text = Strings.StartingPressure.localized
        cell.txtStartPressure_Symbol.placeholder = "PSI / Bar"
        cell.txtStartPressure.text = userDefault.objectForKey("startPressure") as? String
        cell.txtStartPressure_Symbol.text =  userDefault.objectForKey("symbol_startPressure") as? String
        userDefault.synchronize()
        return cell

我的DiveStartTankPressureTableViewCell看起来像这样:

class DiveStartTankPressureTableViewCell: UITableViewCell {

    @IBOutlet weak var lbl_Start_Pressure: UILabel!
    @IBOutlet weak var txtStartPressure: UITextField!
    @IBOutlet weak var txtStartPressure_Symbol: UITextField!

    private(set) var startingTank : String?
    private(set) var startingTankSymbol : String?

    // ---------------------------------------------------------------------------------------------
    // MARK: - UITableVieCell Methods

    //
    //  Called when we are initialized from a storyboard or nib file.
    //
    override func awakeFromNib()
    {
        super.awakeFromNib()
    }

    //
    //  The item has been selected in the table.
    //
    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)
    }

    // ---------------------------------------------------------------------------------------------
    // MARK: - UITextFieldDelegate Method Implementation

    //
    //  We are called when the user is done editing.
    //
    func textFieldDidEndEditing(textField: UITextField)
    {
        startingTank = txtStartPressure.text
        startingTankSymbol = txtStartPressure_Symbol.text
        itemToParse()
    }

    override func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(startingTank, forKey: "startingTank")
        aCoder.encodeObject(startingTankSymbol, forKey: "startingTankSymbol")
    }

    func itemToParse () {

        let updateDiveQuery = PFQuery(className: "divelog")
        updateDiveQuery.whereKey("uuid", equalTo: diveUUID)
        updateDiveQuery.getFirstObjectInBackgroundWithBlock {(objects: PFObject?, error: NSError?) -> Void in

            if error == nil {

                if let updateDiveObject = objects {

                    updateDiveObject["startingTank"]        = self.startingTank
                    updateDiveObject["startingTankSymbol"]      = self.startingTankSymbol

                    updateDiveObject.pinInBackground()
                    updateDiveObject.saveInBackgroundWithBlock {(done:Bool, error:NSError?) in

                        if done {
                            print ("ParseData UPDATED data saved")

                        } else {
                            updateDiveObject.saveEventually()
                        }
                    }

                    if PFUser.currentUser()!.username == nil {
                        updateDiveObject["username"] = "Not Signed in"
                    } else {
                        updateDiveObject["username"] = PFUser.currentUser()!.username
                    }
                    updateDiveObject.saveEventually()

                }
            }
        }
    }
}

任何想法在哪里看?

编辑,添加我的故事板的截图

enter image description here

有趣的更新。我试过"平原"而不是" Group"并将错误更改为以下内容:

Could not cast value of type 'UITableViewCell' (0x10623e278) to 'RLA_DiveLog.DiveStartTankPressureTableViewCell' (0x1022fb330).

3 个答案:

答案 0 :(得分:0)

很可能您忘记使用tableViews设置TankStartCell identifier Attribute inspector,选择原型单元格,请参阅下面的图片。

enter image description here

希望这会有所帮助..

答案 1 :(得分:0)

你是否确定你的细胞也是正确的类型?

enter image description here

答案 2 :(得分:0)

确实很奇怪。

经过一番研究,似乎Xcode正在使用两种不同的故事板。当我点击Main.Storyboard并更新这个故事板时,它没有任何效果,因为我的ViewController使用的是Main.Storyboard(Base)。

不知道这是怎么回事,但这显然是Xcode 8的问题。

希望这可以帮助其他人解决这个奇怪的问题。