我的App有问题。目前,我试图将数据推送到我的PHP脚本。但是,当我按下按钮时,整个应用程序冻结。这是我的代码。
GuestlistViewControler.m文件
//
// GuestlistViewControler.m
// Club La Boom
//
// Created by Kevin Archambault on 2014-04-21.
// Copyright (c) 2014 Club La Boom. All rights reserved.
//
#import "GuestlistViewControler.h"
@implementation GuestlistViewControler
-(IBAction)addData:(id)sender{
NSString *name = self.NameText;
NSString *invite = self.InviteText;
NSString *email = self.EmailText;
NSString *phone = self.CellText;
NSString *date = self.DateText;
NSString *rawStr = [NSString stringWithFormat:@"name=%@&invite=%@&&email=%@&phone=%@&date=%@", name,
invite,
email,
phone,
date];
NSData *data = [rawStr dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:@"http://www.clublaboom.com/guestlist_iphone.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *responseString = [NSString stringWithUTF8String:[responseData bytes]];
NSLog(@"%@", responseString);
NSString *success = @"success";
[success dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%lu", (unsigned long)responseString.length);
NSLog(@"%lu", (unsigned long)success.length);
[self dismissViewControllerAnimated:YES completion:nil]; // Dismiss the viewController upon success
}
@end
GuestlistViewControler.h文件
//
// GuestlistViewControler.h
// Club La Boom
//
// Created by Kevin Archambault on 2014-04-21.
// Copyright (c) 2014 Club La Boom. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
@interface GuestlistViewControler :
UITableViewController {
UITextField *_NameText;
UITextField *_InviteText;
UITextField *_EmailText;
UITextField *_CellText;
UITextField *_DateText;
UIButton *_SubmitButton;
}
@property (strong, nonatomic) IBOutlet UITableViewController *GuestlistViewControler;
@property (nonatomic, retain) IBOutlet UITextField * NameText;
@property (nonatomic, retain) IBOutlet UITextField * InviteText;
@property (nonatomic, retain) IBOutlet UITextField * EmailText;
@property (nonatomic, retain) IBOutlet UITextField * CellText;
@property (nonatomic, retain) IBOutlet UITextField * DateText;
@property (nonatomic, retain) IBOutlet UIButton * SubmitButton;
@end
感谢帮助
答案 0 :(得分:1)
变化:
NSString *name = self.NameText;
NSString *invite = self.InviteText;
NSString *email = self.EmailText;
NSString *phone = self.CellText;
NSString *date = self.DateText;
为:
NSString *name = self.NameText.text;
NSString *invite = self.InviteText.text;
NSString *email = self.EmailText.text;
NSString *phone = self.CellText.text;
NSString *date = self.DateText.text;
答案 1 :(得分:0)
您需要访问UITextField
属性
NSString *name = self.NameText.text;
NSString *invite = self.InviteText.text;
NSString *email = self.EmailText.text;
NSString *phone = self.CellText.text;
NSString *date = self.DateText.text;