ios 故事板警告:原型表单元格必须具有重用标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9808621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:27:29  来源:igfitidea点击:

Storyboard warning: prototype table cells must have reuse identifiers

iphoneiosxcodestoryboard

提问by K.Honda

I am getting this warning from storyboard - prototype table cells must have reuse identifiers.

我从情节提要中收到此警告 - 原型表单元格必须具有重用标识符。

I have renamed the identifier in the attributes inspector but it does not seem to have removed the warning.

我在属性检查器中重命名了标识符,但它似乎没有删除警告。

Any suggestions?

有什么建议?

回答by aleroot

To shut up the warning you have to give a name to the cell identifier :

要关闭警告,您必须为单元格标识符命名:

enter image description here

在此处输入图片说明

回答by bitsand

Another way is to set the Table View 'Prototype Cells' property to zero in Attributes Inspector, if you are defining the cell using a .xib programatically.

如果您使用 .xib 以编程方式定义单元格,另一种方法是在属性检查器中将表视图的“原型单元格”属性设置为零。

Setting prototype cells to 0 in Attributes Inspector

在属性检查器中将原型单元格设置为 0

回答by Dmitry Varavkin

As storyboard is actually XML file, so another trick is to open your storyboard with any text editor (not Xcode!) and try to find all tableViewCell nodes. For example press CMD+F, type <tableViewCell contentMode="scaleToFill"and press Enter. You will probably find out, the rows same to this one:

由于故事板实际上是 XML 文件,因此另一个技巧是使用任何文本编辑器(不是 Xcode!)打开故事板并尝试找到所有 tableViewCell 节点。例如,按CMD+F,键入<tableViewCell contentMode="scaleToFill"并按 Enter。您可能会发现,与此相同的行:

<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="GenericCellID" id="kBr-Qn-Tki">

Please pay your attention on reuseIdentifier="GenericCellID"key value. The rows which fire the warning (without reuse identifiers) will not have such key value. Look nodes above in your text editor and you will see tableViewControllernode with class name you need to check in Xcode's storyboard editor and fix, according to aleroot' answer.

请注意reuseIdentifier="GenericCellID"键值。触发警告的行(没有重用标识符)将没有这样的键值。tableViewController根据 aleroot 的回答,在您的文本编辑器中查看上面的节点,您将看到带有类名的节点,您需要在 Xcode 的故事板编辑器中检查并修复。

回答by Marcel Wassmer

If your Xcode warning still doesn't go away even after you have set the reuseIdentifier, then try Menu "Product -> Clean". This helped for me and after that, the warning didn't show up anymore.

如果设置了重用标识符后 Xcode 警告仍未消失,请尝试菜单“产品 -> 清洁”。这对我有帮助,在那之后,警告不再出现。

回答by Hannele

A hail mary: restarting XCode worked for me (but it was probably just a manual rebuild that was required).

万岁:重新启动 XCode 对我有用(但这可能只是需要手动重建)。

回答by Sitric

Since double-clicking this warning can lead to a bit of a wild goose chase (the specific UITableViewCell doesn't get selected), just wanted to add that while some of these warnings will auto-resolve, some will not.

由于双击此警告可能会导致一些疯狂的追逐(未选择特定的 UITableViewCell),因此只想补充一点,虽然其中一些警告会自动解决,但有些不会

If you are confident you've tagged all your cells in Storyboard, rebuild the project - your warning may disappear (as did mine).

如果您确信已在 Storyboard 中标记了所有单元格,请重建项目 - 您的警告可能会消失(就像我的一样)。

回答by Mili

I got this warning for Xcode 7. I am working with Swift. I did not added the navigation controller for the initial view controller. When I did so.. I got this warning from StoryBoard. What I did is:

我收到 Xcode 7 的警告。我正在使用 Swift。我没有为初始视图控制器添加导航控制器。当我这样做时……我从 StoryBoard 收到了这个警告。我所做的是:

  1. There are two segues
    1. from Navigation Controller to Root view Controller and
    2. from Root View controller to your initial View controller.
  2. Select the segue connecting the root view controller to the initial view controller.
  3. Name the identifier
  4. Select the "Prototype" written part of the controller--> there you will see identifier as an option.
  5. Paste the same name of the identifier as entered earlier.
  1. 有两个segue
    1. 的导航控制器到根视图控制器和
    2. 从根视图控制器到您的初始视图控制器。
  2. 选择将根视图控制器连接到初始视图控制器的 segue。
  3. 命名标识符
  4. 选择控制器的“原型”写入部分--> 在那里您将看到标识符作为一个选项。
  5. 粘贴与之前输入的标识符相同的名称。

The warning goes.. if not clean the sdk :)

警告消失了..如果不清理sdk :)

回答by pkamb

Be sure that you are setting the Reuse Identifieron the object, rather than the Restoration ID. Both are available via the storyboard, and easily confused.

确保您在对象上设置重用标识符,而不是恢复 ID。两者都可以通过故事板获得,并且很容易混淆。

In the storyboard XML file you'll want to be setting reuseIdentifier, not restorationIdentifier.

在情节提要 XML 文件中,您需要设置reuseIdentifier,而不是restorationIdentifier.

回答by Mukesh

This for setting reuse identifier by programmatically

这用于通过编程设置重用标识符

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath*)indexPath 
{
    static NSString *cellIdentifier = @"wot";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    if (!cell)
        cell = [[UITableViewCell alloc] initWithStyle: someStyle reuseIdentifier: cellIdentifier];

    return cell;
}

回答by Tjalsma

I've noticed that this error occurs when you have multiple prototype cells (in the tableview properties) and have not given allof them re-use identifiers.

我注意到当您有多个原型单元格(在 tableview 属性中)并且没有给所有这些单元格重用标识符时,会发生此错误。