gpt4 book ai didi

ios - 在 initWithCoder : what are the keys in the NSCoder (a UINibDecoder)?(用于 UIImageView)

转载 作者:可可西里 更新时间:2023-11-01 03:31:56 26 4
gpt4 key购买 nike

具体来说,我正在尝试查找图像路径。这将是一件非常有用的东西,而且据我所知,没有人知道如何获得。我查看了生成的 nib 文件中的 key ,我能够在其中看到图像 URL (test.jpg),但找不到获取它的 key 。键“UIImage”返回实际已经构建的图像(通过 initWithCGImageStored:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation 和神秘的 UIKit 函数调用 GetImageAtPath< 构建 调用提到的 init 调用),所以这没有帮助。

我还尝试使用 NSKeyedArchiver 将 UIImageView 写入磁盘,但这些值似乎也不正确,test.jpg 值也不存在。

如果没有人能解决这个问题——有人知道如何将二进制文件作为文本读入吗?我可以只通读 nib 并解析出 URL,这总比没有好,但是无论我尝试什么格式,NSString 的构造函数都会失败。

最佳答案

您是否尝试过在 NSKeyedUnarchiver 上实现一个类别并以这种方式捕获 key ?快速实现和调查,你会发现关键是“UIResourceName”。但是请记住,keyed unarchiver 仅返回当前解码范围内的 key 对象。这意味着您无法从根部查询此键,您必须深入挖掘对象层次结构。

以下是记录所有链接资源的代码。这取决于你如何使用它。当 UIImage 被解码时,它也会记录。如果需要,您可以在此处返回自己的类(class)。

@interface NSKeyedUnarchiver (MyKeyedUnarchiver)
@end

@implementation NSKeyedUnarchiver (MyKeyedUnarchiver)

- (id) mydecodeObjectForKey:(NSString *)key
{
id obj = [self mydecodeObjectForKey:key];
if ( [key isEqualToString:@"UIResourceName"] )
NSLog(@"The linked resource name is: %@", obj);
return obj;
}

- (Class) myclassForClassName:(NSString *)codedName
{
if ( [codedName isEqualToString:@"UIImageNibPlaceholder"] )
NSLog(@"Decoding a UIImage");
return [self myclassForClassName:codedName];
}

+ (void) load
{
SEL origM = @selector( decodeObjectForKey: );
SEL newM = @selector( mydecodeObjectForKey: );
method_exchangeImplementations( class_getInstanceMethod( self, origM ), class_getInstanceMethod( self, newM ) );

origM = @selector( classForClassName: );
newM = @selector( myclassForClassName: );
method_exchangeImplementations( class_getInstanceMethod( self, origM ), class_getInstanceMethod( self, newM ) );
}

@end

希望这对您有所帮助。

关于ios - 在 initWithCoder : what are the keys in the NSCoder (a UINibDecoder)?(用于 UIImageView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10016683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com