我想要一個名稱字段,人們可以放在那裏名稱,它會發送到一個PHP頁面。空間NSURL連接
我有這個工作沒有與此代碼的空間...
- (IBAction)Submit:(id)sender {
NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text];
NSURL *url=[NSURL URLWithString:strURL];
self.request=[NSURLRequest requestWithURL:url];
self.nsCon=[[NSURLConnection alloc] initWithRequest:self.request delegate:self];
NSLog(@"out put = %@", self.request);
}
但只要我使用空間加法器修復,它不會通過我的PHP頁面被拾起,埃文儘管日誌說它的工作。
- (IBAction)Submit:(id)sender {
NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=", nameField.text];
strURL = [strURL stringByAppendingString:nameField.text];
strURL = [strURL stringByAppendingString:@"'"];
strURL = [strURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSURL *url=[NSURL URLWithString:strURL];
self.request=[NSURLRequest requestWithURL:url];
self.nsCon=[[NSURLConnection alloc] initWithRequest:self.request delegate:self];
NSLog(@"out put = %@", self.request);
}
有我有一個語法錯誤,或以錯誤的方式接近這一方法?
我.h文件中
#import <UIKit/UIKit.h>
@interface ContactViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, NSURLConnectionDataDelegate>{
IBOutlet UITextField *nameField;
}
- (IBAction)Submit:(id)sender;
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (strong) NSURLConnection *nsCon;
@property (strong) NSURLConnection *request;
@property (strong) NSURLConnection *receivedData;
@end
感謝
作爲一個側面說明,可能不會解決您的問題,而不是stringByReplacingOccurrencesOfString方法,你應該使用[unescapedString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]。 – 2013-03-06 16:54:14