gpt4 book ai didi

ios - 连接到原型(prototype)单元时无法使单元出列错误

转载 作者:行者123 更新时间:2023-11-30 13:05:31 25 4
gpt4 key购买 nike

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

我在“案例”中添加了一些特定用途的单元格。

我收到错误“无法使具有标识符 TankStartCell 的单元出列 - 必须为标识符注册 Nib 或类,或者连接 Storyboard 中的原型(prototype)单元”,但是场景已设置作为原型(prototype)单元。

相关单元的标识符中确实有“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()

}
}
}
}
}

有什么想法可以去哪里看吗?

编辑,添加我的 Storyboard的屏幕截图

enter image description here

有趣的更新。我尝试了“Plain”而不是“Group”,错误更改为以下内容:

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

最佳答案

很可能您忘记通过选择原型(prototype)单元格来使用属性检查器设置您的tableViews TankStartCell identifier参见图片下面..

enter image description here

希望这有帮助..

关于ios - 连接到原型(prototype)单元时无法使单元出列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39424196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com