我的應用程序出現問題。目前,我試圖將數據壓入我的PHP腳本。但是,當我按下按鈕時,整個App凍結。這是我的代碼。不兼容的指針使用'UITextField *'類型的表達式初始化'NSString *'類型
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
感謝您的幫助
錯誤消息對我來說很清楚的財產的.text。它是說你正在使用'UITextField *'在哪裏期待'NSString *'類型 –