必须为该标识符注册一个笔尖或一个类,或快速将一个原型单元连接到情节提要中

时间:2018-09-26 09:22:44

标签: ios

我的模特:

  enum NHAnswerType:Int
    {

        case NHAnswerCheckboxButton = 1
        case NHAnswerRadioButton = 2
        case NHAnswerSmileyButton = 3
        case NHAnswerStarRatingButton = 4
        case NHAnswerTextButton = 5
    }


    class NH_QuestionListModel: NSObject {

        var dataListArray33:[NH_OptionsModel] = []


        var id:Int!
        var question:String!
        var buttontype:String!
        var options:[String]?
        var v:String?
        var answerType:NHAnswerType?


        var optionsModelArray:[NH_OptionsModel] = []
        init(dictionary :JSONDictionary) {

            guard   let question = dictionary["question"] as? String,
                let typebutton = dictionary["button_type"] as? String,

                    let id = dictionary["id"] as? Int
                 else {
                    return

            }
           // (myString as NSString).integerValue


            self.answerType = NHAnswerType(rawValue: Int(typebutton)!)
            print(self.answerType?.rawValue)


            if let options = dictionary["options"] as? [String]{
                print(options)

               print(options)


                for values in options{

                    print(values)

                    let optionmodel = NH_OptionsModel(values: values)
                    self.optionsModelArray.append(optionmodel)

                }


            }


            self.buttontype = typebutton
            self.question = question
            self.id = id

                       }

    }

在viewcontroller中:

 override func viewDidLoad() {



            super.viewDidLoad()

      self.tableview?.register(NH_SmileyCell.nib, forCellReuseIdentifier: NH_SmileyCell.identifier)
            self.tableview?.register(NH_StarRatingCell.nib, forCellReuseIdentifier: NH_StarRatingCell.identifier)
            self.tableview?.register(NH_CheckBoxCell.nib, forCellReuseIdentifier: NH_CheckBoxCell.identifier)
            self.tableview?.register(NH_RadioTypeCell.nib, forCellReuseIdentifier: NH_RadioTypeCell.identifier)
    }
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

            let model = questionViewModel.titleForHeaderInSection(atsection: indexPath.row)
           // print(model.answerType?.hashValue)
            print(model.answerType)
            print(model.answerType?.rawValue)


            switch model.answerType {
            case .NHAnswerRadioButton?:
                if let cell = tableview.dequeueReusableCell(withIdentifier: NH_RadioTypeCell.identifier, for: indexPath) as? NH_RadioTypeCell {
                    cell.textLabel?.text = "dfdsfgs"
                  //  cell.item = item
                    return cell
                }
            case .NHAnswerCheckboxButton?:
                if let cell = tableView.dequeueReusableCell(withIdentifier: NH_CheckBoxCell.identifier, for: indexPath) as? NH_CheckBoxCell {
                    cell.textLabel?.text = "dfdsfgs"
                    //  cell.item = item
                    return cell
                }
            case .NHAnswerSmileyButton?:
                if let cell = tableView.dequeueReusableCell(withIdentifier: NH_SmileyCell.identifier, for: indexPath) as? NH_SmileyCell {
                    cell.textLabel?.text = "dfdsfgs"
                    //  cell.item = item
                    return cell
                }
            case .NHAnswerStarRatingButton?:
                if let cell = tableView.dequeueReusableCell(withIdentifier: NH_StarRatingCell.identifier, for: indexPath) as? NH_StarRatingCell {
                    cell.textLabel?.text = "dfdsfgs"
                    //  cell.item = item
                    return cell
                }
    //        case .NHAnswerTextButton?:
    //            if let cell = tableView.dequeueReusableCell(withIdentifier: NH_TextCell.identifier, for: indexPath) as? NH_TextCell{
    //                //  cell.item = item
    //                return cell
    //            }
                default:
                return UITableViewCell()
            }

在无线电类型单元格中:

 class NH_RadioTypeCell: UITableViewCell {

        @IBOutlet weak var questionLabel: UILabel?

        var item: NH_QuestionViewModelItem? {
            didSet {
                guard let item = item as? NHQuestionViewModelQuestionNameItem else {
                    return
                }

                questionLabel?.text = item.question

            }
        }


        static var nib:UINib {
            return UINib(nibName: identifier, bundle: nil)
        }

        static var identifier: String {
            return String(describing: self)
        }



        override func awakeFromNib() {
            super.awakeFromNib()
            // Initialization code
        }

        override func setSelected(_ selected: Bool, animated: Bool) {
            super.setSelected(selected, animated: animated)

            // Configure the view for the selected state
        }

    }

这总是产生以下错误消息:

  

NH_CheckBoxCell-必须为该标识符注册一个笔尖或一个类,或者   将原型单元连接到情节提要中'

如何解决此问题?

在表格视图中快速注册单元格时,我应该做什么更改?

0 个答案:

没有答案