ios 错误:CUICatalog:提供的资产名称无效:(空)或无效的比例因子:2.000000

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22011106/
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 23:34:30  来源:igfitidea点击:

Error: CUICatalog: Invalid asset name supplied: (null), or invalid scale factor : 2.000000

iosobjective-cxcode5

提问by manish singh

TableViewApplication[1458:70b] CUICatalog: Invalid asset name supplied: (null), or invalid scale factor: 2.000000

Screenshot added

添加了截图

Getting this warning while working with TableViewController. How to rectify this error and which block is affected?

使用 TableViewController 时收到此警告。如何纠正此错误以及影响哪个块?

回答by tt.Kilew

This one appears when someone is trying to put nilin [UIImage imageNamed:]

这一次出现,当有人试图把nil[UIImage imageNamed:]

Add symbolic breakpoint for [UIImage imageNamed:]Symbolic breakpoint example

添加符号断点 [UIImage imageNamed:]符号断点示例

Add $arg3 == nilcondition on Simulator, $r0 == nilcondition on 32-bit iPhone, or $x2 == nilon 64-bit iPhone.

$arg3 == nil在模拟器$r0 == nil上添加条件,在 32 位 iPhone 或$x2 == nil64 位 iPhone 上添加条件。

Run your application and see where debugger will stop.

运行您的应用程序并查看调试器将在哪里停止。

P.S. Keep in mind this also happens if image name is empty string. You can check this by adding [(NSString*)$x2 length] == 0to the condition.

PS 请记住,如果图像名称为空字符串,也会发生这种情况。您可以通过添加[(NSString*)$x2 length] == 0到条件来检查这一点。

回答by Fabio

This error (usually) happens when you try to load an image with [UIImage imageNamed:myImage]but iOS is not sure if myImageis really a NSStringand then you have this warning.

当您尝试加载图像时(通常)会发生此错误,[UIImage imageNamed:myImage]但 iOS 不确定是否myImage真的是 a NSString,然后您会收到此警告。

You can fix this using:

您可以使用以下方法解决此问题:

[UIImage imageNamed:[NSString stringWithFormat:@"%@", myImage]]

Or you can simply check for the lengthof the name of the UIImage:

或者您可以简单地检查以下length名称的名称UIImage

if (myImage && [myImage length]) {

    [UIImage imageNamed:myImage];
}

回答by robotspacer

Since the error is complaining that the name you gave is (null), this is most likely caused by calling [UIImage imageNamed:nil]. Or more specifically, passing in a variable hasn't been set, so it's equal to nil. While using stringWithFormat:would get rid of the error, I think there's a good chance it's not actually doing what you want. If the name you supply is a nilvalue, then using stringWithFormat: would result in it looking for an image that is literally named "(null)", as if you were calling [UIImage imageNamed:@"(null)"].

由于错误是抱怨您提供的名称是(null),这很可能是由调用[UIImage imageNamed:nil]. 或者更具体地说,传入的变量尚未设置,因此它等于nil. 虽然使用stringWithFormat:可以消除错误,但我认为很有可能它实际上并没有按照您的意愿行事。如果您提供的名称是一个nil值,那么使用 stringWithFormat: 将导致它查找字面上名为“(null)”的图像,就好像您正在调用[UIImage imageNamed:@"(null)"].

Something like this is probably a better option:

像这样的事情可能是更好的选择:

if (name) {
    UIImage *image = [UIImage imageNamed:name];
} else {
    // Do something else
}

You might want to set a breakpoint in Xcode on that "Do something else" line, to help you figure out why this code is getting called with a nil value in the first place.

您可能希望在 Xcode 中的“做其他事情”行上设置一个断点,以帮助您弄清楚为什么首先使用 nil 值调用此代码。

回答by ginchly

In Xcode 6.4, this seems to occur when using "Selected Image" for a tab bar item in the storyboard, even if it's a valid image.

在 Xcode 6.4 中,这似乎发生在对故事板中的选项卡栏项使用“选定图像”时,即使它是有效图像。

enter image description here

在此处输入图片说明

This doesn't actually seem to set the selected state image anyway, so it needs to be defined in User Defined Runtime Attributes, and removed from the SelectedImage attribute of the Tab Bar Item

这实际上似乎并没有设置选定的状态图像,因此它需要在用户定义的运行时属性中定义,并从选项卡栏项的 SelectedImage 属性中删除

enter image description here

在此处输入图片说明

回答by Rahul Mathur

In my case i was passing [UIImage imageNamed:@""] which caused me to show the warning. Just add breakpoints to all the lines where you have used imageNamed and the debug the line where you find the warning.

就我而言,我正在传递 [UIImage imageNamed:@""] 这导致我显示警告。只需将断点添加到您使用 imageNamed 的所有行,并调试您发现警告的行。

回答by idrougge

This happened to me after a storyboard was split into several (the actual change happened when I was on holidays, so I don't know exactly how it was done).

这发生在我把故事板分​​成几个之后(实际的变化发生在我假期的时候,所以我不知道它是如何完成的)。

After inspecting the XML of the storyboards, I found that an image reference which previously had pointed to "bottomBar" in the assets catalogue instead pointed to imageView:fFo-1g-jzs:image.

在检查故事板的 XML 后,我发现之前在资产目录中指向“bottomBar”的图像引用改为指向imageView:fFo-1g-jzs:image.

At the end of the XML file under the <resources>tag was tag named <image name="imageView:fFo-1g-jzs:image">containing a big mutableDatablob.

<resources>标记下的 XML 文件的末尾是<image name="imageView:fFo-1g-jzs:image">一个名为的标记,其中包含一个大mutableDatablob。

After resetting the image reference in the storyboard and removing the blob, the error went away.

重置故事板中的图像引用并删除 blob 后,错误消失了。

回答by Aks

You are supplying some invalid image name, so need to validate before putting it you can do any of the above ways whichever make sense for your code or like

您正在提供一些无效的图像名称,因此需要在放置之前进行验证,您可以执行上述任何对您的代码或类似方法有意义的方法

if (iconImageName && [iconImageName length])
{

    [UIImage imageNamed:iconImageName];
}
else
{
     iconImageName.hidden = YES;
}

Hope it will help!!!!

希望它会有所帮助!!!!

回答by passwind

I have just fixed this error. Just check the usage of the [UIImage imageNamed:(NSString*) imageName]function. If the imageNameis nil, then error occurs.

我刚刚修复了这个错误。只需检查该[UIImage imageNamed:(NSString*) imageName]函数的用法。如果imageNamenil,则发生错误。

回答by Bharath

The Reason to the error is passing a nil value to the "imageNamed:" method. To avoid this, you can hide your imageView when you try to pass the nil value. The chances may occur in reusing the imageViews in UITableView or may be in scrollViews.

错误的原因是将 nil 值传递给“imageNamed:”方法。为避免这种情况,您可以在尝试传递 nil 值时隐藏 imageView。重用 UITableView 中的 imageViews 或可能在 scrollViews 中可能会发生这种情况。

I avoided the warning with the below check :

我通过以下检查避免了警告:

UIImageView *your_image_view;
NSString *imageName;
if(imageName && imageName.length){
 your_image_view.hidden = NO;
 your_image_view.image = [UIImage imageNamed:imageName];
}
else {
 your_image_view.hidden = YES;
}

回答by Meilbn

I got this warning when I load image use [[UIImage imageNamed:normalStr] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], than, I change to [UIImage imageNamed:normalStr], warning was gone.

我在加载图像使用时收到此警告[[UIImage imageNamed:normalStr] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal],然后更改为[UIImage imageNamed:normalStr]警告消失了。