2017-09-27 98 views
-1

當我將字符串轉換爲NSURL時,我得到了一些東西。 我的代碼編號...如何將字符串轉換爲url?

NSString *urlString = [[NSString alloc]initWithFormat:@"http://host name/index.php?id=%@&mob=%@&name=%@&mail=%@&m=23", self.deviceId, self.pnumber, self.name, self.email]; 
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 
NSURL *urlPattern = [NSURL URLWithString:urlString]; 
NSLog(@"%@", urlPattern); 

http://host name/index.php?dev_id=73EA1D1D-E6E3-485C-883D-DF952E116&mob=%3CUITextField:%200x7fe247063c00;%20frame%20=%20(0%20128.333;%20310.667%2040.6667);%20text%20=%20'';%20opaque%20=%20NO;%20autoresize%20=%20RM+BM;%20gestureRecognizers%20=%20%3CNSArray:%200x608000244c50%3E;%20layer%20=%20%3CCALayer:%200x60800003eee0%3E%3E&name=%3CUITextField:%200x7fe247055800;%20frame%20=%20(0%2044;%20310.667%2040.3333);%20text%20=%20'';%20opaque%20=%20NO;%20autoresize%20=%20RM+BM;%20gestureRecognizers%20=%20%3CNSArray:%200x608000244410%3E;%20layer%20=%20%3CCALayer:%200x60800003e240%3E%3E&mail=%3CUITextField:%200x7fe24601ae00;%20frame%20=%20(0%20213;%20310.667%2040.3333);%20text%20=%20'';%20opaque%20=%20NO;%20autoresize%20=%20RM+BM;%20gestureRecognizers%20=%20%3CNSArray:%200x608000243c90%3E;%20layer%20=%20%3CCALayer:%200x60c000038580%3E%3E&m=23 

如何串NSURL

+0

問題是什麼你好嗎? –

+0

你的代碼是好的,正確的是你遇到的問題 –

+0

你編碼你的nsstring,並且你已經在上面的代碼中將nsstring轉換爲nsurl。你的要求是什麼? –

回答

5

也許你是urlString分配文本框轉換。檢查self.pnumber是否爲文本字段或字符串。如果textField設置爲self.pnumber.text,並同樣檢查所有數據。

變化self.pnumber, self.name, self.emailself.pnumber.text, self.name.text, self.email.text

使用像

NSString *urlString = [[NSString alloc]initWithFormat:@"http://host name/index.php?id=%@&mob=%@&name=%@&mail=%@&m=23", self.deviceId, self.pnumber.text, self.name.text, self.email.text];