简体   繁体   English

奇怪的UITableView错误:将故事板中的静态单元出队时出现“断言失败”

[英]Strange UITableView error: “Assertion Failure” on dequeuing static cells in storyboard

I am getting this error: *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] with static cells. 我收到此错误:***带有静态单元格的-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]中的断言失败。

My code is in Swift (the reuse identifiers are strings set as constants in the file): 我的代码在Swift中(重用标识符是在文件中设置为常量的字符串):

... private let topTableViewCellIdentifier = "topTableViewCell" private let bottomTableViewCellIdentifier = "bottomTableViewCell" ...

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

    let reuseIdentifier = (indexPath.section == 0) ? topTableViewCellIdentifier : bottomTableViewCellIdentifier


    let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath)
    return cell
}

I have searched stack overflow for this error, and found a bunch of answers all basically saying the same thing: make sure the reuse identifier is the same as the one for the cell in the storyboard. 我已经在堆栈溢出中搜索了此错误,并找到了一堆基本上都说相同的答案:确保重用标识符与情节提要中单元的标识符相同。

However, in my case, it is. 但是,就我而言。

I have confirmed this repeatedly, and have cut and pasted from one to the other repeatedly in order to ensure this is the case. 我已经反复确认了这一点,并反复将其从另一个粘贴到另一个,以确保确实如此。 Xcode clearly indicates that the correct value is being set. Xcode清楚地表明正在设置正确的值。 I have cleaned. 我已经打扫过了 I have even restarted. 我什至已经重新开始。 I have done everything I can think of, and it does not see the cells in the storyboard. 我已经做了所有我能想到的事情,并且看不到情节提要中的单元格。 They are set as static, and The correct class is being set in the inspector (though that should be clear by the fact that it gets the correct value) 它们被设置为静态的,并且在检查器中设置了正确的类(尽管通过获取正确的值这一点应该很清楚)

在此处输入图片说明

Any thoughts or assistance would be appreciated. 任何想法或协助将不胜感激。 I am using El Capitan and Xcode 7. 我正在使用El Capitan和Xcode 7。

If you are attempting to use a static layout for a table view, you typically do not implement tableView:cellForRowAtIndexPath: , the UITableViewController does this for you. 如果您尝试为表视图使用静态布局,则通常不实现tableView:cellForRowAtIndexPath:UITableViewController会为您执行此操作。 It is invalid to call the dequeueReusableCellWithIdentifier:forIndexPath: method for a statically configured UITableView (as the error indicates). 为静态配置的UITableView调用dequeueReusableCellWithIdentifier:forIndexPath:方法是无效的(如错误所示)。

Make sure your UITableView is set to Dynamic Prototypes 确保您的UITableView设置为Dynamic Prototypes

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM