0

我使用来自 Dimitris 的URL 解析器类,但是当 init 对象出现时我遇到了一个问题initWithURLString

- (id) initWithURLString:(NSString *)url{
    self = [super init];
    if (self != nil) {
        NSString *string = url;
        NSScanner *scanner = [NSScanner scannerWithString:string];
        [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?"]];
        NSString *tempString;
        NSMutableArray *vars = [NSMutableArray new];
        //ignore the beginning of the string and skip to the vars
        [scanner scanUpToString:@"?" intoString:nil];
        while ([scanner scanUpToString:@"&" intoString:&tempString]) {
            [vars addObject:[tempString copy]];
        }
        self.variables = vars;
    }
    return self;
}

在线[scanner scanUpToString:@"?" intoString:nil];我得到一个错误:

[NSURL 长度]:无法识别的选择器发送到实例 0x1f8c2050

这怎么可能?

编辑:也许你想知道我如何调用 URLParser:

URLParser *urlParser = [[URLParser alloc]initWithURLString:[info valueForKey:UIImagePickerControllerReferenceURL]];

UIImagePickerControllerReferenceURL 值为:assets-library://asset/asset.PNG?id=8D2F0449-11A3-4962-9D60-C446831645D7&ext=PNG

4

1 回答 1

1

您将 NSURL 传递给 initWithURLString,但您应该像这样将它与 NSString 一起使用:

NSString* urlString = [NSString stringWithFormat:@"%@",[info valueForKey:UIImagePickerControllerReferenceURL]];
URLParser *parser = [[[URLParser alloc] initWithURLString:urlString] autorelease];
于 2012-12-04T08:31:46.153 回答