我试图有一个名称字段,人们可以在那里输入名称,它将发送到一个 php 页面。
我已经用这个代码在没有空格的情况下工作了......
- (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
谢谢