无法使用标识符“GroupMessageCell”

时间:2016-05-18 01:16:57

标签: ios swift tableview

我在标签中显示了两个tableView。对于打开的第一个,没有错误,但在选择第二个选项卡时,会出现错误:

2016-05-17 21:07:23.730 FeastApp[11007:172938] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:6573
2016-05-17 21:07:23.736 FeastApp[11007:172938] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier GroupMessageCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

即使我已将行标识符设置为:GroupMessageCell

enter image description here

在我的嵌套TableView中:

enter image description here

和班级:

class GroupMessageList: UITableViewController {

    var getGroups: Firebase!
    var groups: [Group] = []

    override func viewDidLoad() {
        super.viewDidLoad()

        getGroupsWithMessages()

    }

    override func viewWillAppear(animated: Bool) {

        super.viewWillAppear(animated)
    }

    // MARK: - Table View

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return self.groups.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("GroupMessageCell", forIndexPath: indexPath)
        let group: Group

        group = groups[indexPath.row]

        // Update the rows with the proper object
        cell.textLabel!.text = "\(group.groupName) \(group.groupID)"
        return cell
    }

    func getGroupsWithMessages() {

        getGroups = Firebase(url: Global.sharedInstance.firebaseMainURL + "usersGroups/" + Global.sharedInstance.userID)

        self.getGroups.observeSingleEventOfType(.Value, withBlock: { snapshot in

            print(snapshot)

            for detailData in snapshot.children {

               // print(detailData.value)

               self.groups.append(Group(groupName: "test", groupID: detailData.key))

                print(self.groups.count)

            }

            self.tableView!.reloadData()

        })
    }        
}

如何防止发生此错误?

2 个答案:

答案 0 :(得分:2)

您尚未为 GroupMessageCell

设置类

选择故事板和

enter image description here

然后

enter image description here

验证Class GroupMessageCell

设置标识符

enter image description here

答案 1 :(得分:1)

三个潜力问题区域:

  1. 确保单元格标识符存在 - [根据您的详细信息看起来很好]

  2. 您是否在故事板上将TableViewController的类设置为GroupMessageList,如下所示:custom table view class

  3. 运行Product>后是否仍然出现错误?干净。

  4. 希望其中一个有帮助!