【问题标题】:CUICatalog: Invalid asset name supplied: , or invalid scale factor: 2.000000CUICatalog:提供的资产名称无效:或比例因子无效:2.000000
【发布时间】:2014-06-09 07:46:00
【问题描述】:

我有一个 UiVIewController,我在其中拖动了一个表格视图并放置了所有需要的连接,例如委托和数据源,它工作得很好,一切都很好。我试图为这个表格视图设置一个背景,但我得到了这个奇怪的错误

CUICatalog: Invalid asset name supplied: , or invalid scale factor: 2.000000

我尝试使用这种方法设置背景:

UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mypredictions_bg.png"]];
[tempImageView setFrame:self.tableView.frame];

self.tableView.backgroundView = tempImageView;

我错过了什么?我检查了图片的名字是正确的

【问题讨论】:

  • 您的代码中是否有类似[UIImage imagenamed:@""]; 的声明?因为当您尝试使用[UIImage imageNamed:myImage] 加载图像但iOS 未找到名称为myImage 的图像时会出现警告
  • @BuntyM 我检查了那里的所有文件..我尝试以相同的方式加载,但在 tableviewcontroller 中它工作得很好,但在我的情况下它不会

标签: ios objective-c xcode uitableview uiviewcontroller


【解决方案1】:

我创建了一个调试类,它可以调配 imageNamed,以便您可以获取有关发生这种情况的调试跟踪。

您需要安装 JRSwizzle 才能使用它。

https://github.com/rentzsch/jrswizzle

#import "UIImageDebugger.h"
#import "JRSwizzle.h"


@implementation UIImageDebugger

+ (void)startDebugging
{
    static dispatch_once_t once;

    dispatch_once(&once, ^{

        NSError *error=NULL;

        [UIImage jr_swizzleClassMethod:@selector(imageNamed:)
                       withClassMethod:@selector(hs_xxz_imageNamed:)
                                 error:&error];


        if (error)
        {
            NSLog(@"error setting up UIImageDebugger : %@",error);
        }
        else
        {
            NSLog(@"!!!!!!!!!!!!!!!!!!!!  UIImage swizzle in effect - take this out for release!!");
        }


    });

}

@end

@interface UIImage (UIViewDebugger)

+ (UIImage*)hs_xxz_imageNamed:(NSString *)name;

@end


@implementation UIImage (UIViewDebugger)

+ (UIImage*)hs_xxz_imageNamed:(NSString *)name
{
    if (!name)
    {
        NSLog(@"null image name at \n%@",[NSThread callStackSymbols]);
    }

    UIImage *image=[self hs_xxz_imageNamed:name];

    if (!image)
    {
        NSLog(@"failed to make image at \n%@",[NSThread callStackSymbols]);
    }

    return image;
}

@end

【讨论】:

  • 您不需要调配方法,您可以在该方法处设置断点并检查变量。在断点面板 (cmd+7) 中单击底部的小 + 并添加一个名称为“+[UIImage imageNamed:]”的符号断点。您甚至可以设置中断条件,并在遇到断点时向 lldb 输出命令。
  • @puppybits - 你将如何设置条件?我熟悉在我自己的代码的上下文中设置条件 - 但是对于符号断点,我不确定如何访问输入(名称)或返回值来查询它们。
  • @ConfusedVorlon,这很棒。将其合并到项目中,以帮助我们在错误地从项目中删除资源文件时找到所有位置。
【解决方案2】:

在我的例子中,我为 UIImageView 和 UITextfied 创建了类别, 在那,有时我不需要图像,那次我提供了@“”(即空字符串),它发生了问题,经过一些研发后我只提供“nil”而不是@“”,它解决了我的警告,所以也许这种类型的警告会在没有得到正确的图像时发生。

【讨论】:

    【解决方案3】:

    在我的情况下,是指向错误的 viewController。 我指向处理基于页面的 ViewController 内容的 viewController,而不是链接到 pageContentViewController 和 PageViewController 链接的 viewController。希望这会有所帮助。

    【讨论】:

      【解决方案4】:

      如果您的图像类型是 png,则不必将其替换为图像文件名的末尾,因为默认的 XCode 图像类型已经是 png。试试这个;

      UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"mypredictions_bg"]]];
      

      【讨论】:

        猜你喜欢
        • 2023-03-13
        • 2014-10-26
        • 2014-03-24
        • 2014-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-15
        • 1970-01-01
        相关资源
        最近更新 更多