Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将UITouchSevent编码为NSData时出错_Ios_Objective C_Nsdata_Nskeyedarchiver_Objective C Category - Fatal编程技术网

Ios 将UITouchSevent编码为NSData时出错

Ios 将UITouchSevent编码为NSData时出错,ios,objective-c,nsdata,nskeyedarchiver,objective-c-category,Ios,Objective C,Nsdata,Nskeyedarchiver,Objective C Category,我有一个NSDictionary,其中包含一些对象:一组UITouches、一个UIEvent和一个NSString 当我尝试将字典编码为NSData时,字符串编码正确。我对UITouch进行编码时出错,但我找到了一种方法,用一些代码扩展类,以便对UITouch进行编码。但是,我仍然无法对UIEvent(实际上是UITouchesEvent)进行编码。如何扩展UIEvent或UIInternalEvent以使其可编码到NSData 我用于编码/解码的方法: -(NSString *)string

我有一个NSDictionary,其中包含一些对象:一组UITouches、一个UIEvent和一个NSString

当我尝试将字典编码为NSData时,字符串编码正确。我对UITouch进行编码时出错,但我找到了一种方法,用一些代码扩展类,以便对UITouch进行编码。但是,我仍然无法对UIEvent(实际上是UITouchesEvent)进行编码。如何扩展UIEvent或UIInternalEvent以使其可编码到NSData

我用于编码/解码的方法:

-(NSString *)stringFromDictionary:(NSDictionary *)dict{
    NSMutableData *data = [[NSMutableData alloc] init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:dict forKey:@"dictKey"];
    [archiver finishEncoding];

    return [Base64 encode:data];
}

-(NSDictionary *)dictionaryFromString:(NSString *)string{
    NSData *data = [[NSMutableData alloc] initWithData:[Base64 decode:string]];
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    NSDictionary *myDictionary = [unarchiver decodeObjectForKey:@"dictKey"];
    [unarchiver finishDecoding];
    return myDictionary;

}
我得到的错误是:

-[UITouchesEvent encodeWithCoder:]: unrecognized selector sent to instance

如果我遗漏了任何有关调试的重要信息,请告诉我。谢谢

您必须使用
UITouch
UITouchesEvent
调整协议。这意味着它必须支持以下方法:

- (id)initWithCoder:(NSCoder *)decoder;
- (void)encodeWithCoder:(NSCoder *)encoder;

我自己也没试过,但如果你在班级里这样做的话,它应该会起作用。困难在于找出您需要编码的内容,以便能够再次解码为正确的实例(如果您需要的话)。

您必须使用
UITouch
UITouchesEvent
调整协议。这意味着它必须支持以下方法:

- (id)initWithCoder:(NSCoder *)decoder;
- (void)encodeWithCoder:(NSCoder *)encoder;

我自己也没试过,但如果你在班级里这样做的话,它应该会起作用。困难在于找出您需要编码的内容,以便能够再次解码为正确的实例(如果您需要的话)。

谢谢,但正如我所说,我已经有了UITouch编码。我正试图找出如何使用UITouchesEvent来实现这一点。我的错,那么当然你必须在
UITouchesEvent
类中实现这一点。但我认为这并不容易。谢谢,但正如我所说,我已经有了UITouch编码。我正试图找出如何使用UITouchesEvent来实现这一点。我的错,那么当然你必须在
UITouchesEvent
类中实现这一点。但我认为这并不容易。