2014-02-24 40 views
2

這是我的代碼使用JSON來從一個MySQL表中的數據:NSCFString absoluteURL例外

//URL definition where php file is hosted 

    int categoriaID = [[categoriaDescription objectForKey:@"idCategoria"] intValue]; 

    NSString *string = [NSString stringWithFormat:@"%d", categoriaID]; 
    NSLog(@"CATEGORIA ID STRING %@",string); 
    NSMutableString *ms = [[NSMutableString alloc] initWithString:@"http://mujercanariasigloxxi.appgestion.eu/app_php_files/categoriaslist.php?id="]; 
    [ms appendString:string]; 
    // URL request 
    NSLog(@"URL = %@",ms); 
    NSURLRequest *request = [NSURLRequest requestWithURL:ms]; 
    //URL connection to the internet 
    [[NSURLConnection alloc]initWithRequest:request delegate:self]; 

記錄的網址是正確的,但應用程序將引發異常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 

我猜錯誤應該在上面的代碼中,但我不明白爲什麼。歡迎任何幫助。

回答

12

我認爲你的代碼是錯誤的。

NSURLRequest * request = [NSURLRequest requestWithURL:ms];

應當改變:

的NSURLRequest *請求= [的NSURLRequest requestWithURL:[NSURL URLWithString:MS]];

+0

是的,你是對的,謝謝@TanVu。 – mvasco

相關問題