我正在開發Twitter API到我的應用程序。在我的應用程序中,我想以動態方式顯示UITexField中帶有解析XML鏈接的小url。靜態地,我可以在UITextField中顯示細小的網址,但是動態地,我無法顯示小網址。請幫幫我!問題與微小的URL
代碼:靜態地(精細工作),
NSURL *url = [NSURL URLWithString"http://tinyurl.com/api-create.php?
url=https://gifts.development.xxxxx.edu/xxxx/Welcome.aspx?appealcode=23430"];
NSString *link = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
動態,
NSString * tiny = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php? url=%@", shtUrl];//shtUrl is parsed string
NSURL *url = [NSURL URLWithString:tiny];
NSString *link = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
在上面,動態應用,而無需警告和錯誤,但網址運行不顯示,當我檢查調試器, url和link都顯示爲零值。但是shtUrl正確地顯示整個url值。
我嘗試過所有的NSURL類和實例方法和字符串方法。
謝謝,現在我刪除了空間,所以NSURL正確播種了鏈接。但仍然鏈接變量只顯示零值。 – Sivanathan 2010-07-01 14:22:19
如果shtUrl爲「http://stackoverflow.com」爲例,那麼tiny和url的值是什麼?使用NSLog或調試器來檢查值?手動(使用瀏覽器或wget/curl)手動點擊url時,生成的url是否工作?問題可能與需要在shtUrl中使用urlencoding轉義特殊字符有關嗎? – 2010-07-01 15:09:52
非常感謝!我解決了刪除特殊字符,換行符和所有。 – Sivanathan 2010-07-01 15:28:51