所以我有代碼提交數據到PHP腳本。這個想法是代碼將數據插入數據庫。發生這種情況,返回的字符串將是「SUCCESSFUL」,否則,「失敗」。現在,我希望當成功的價值返回時,它會加載另一個視圖,說謝謝(標籤)。我怎樣才能做到這一點?當結果正確時加載另一個視圖控制器
代碼:
(IBAction)saveDataAction:(id)sender {
NSString *lEventTitle = [NSString stringWithFormat:@"var=%@",eventTitle.text];
NSString *lEventDesc = [NSString stringWithFormat:@"var=%@",eventDescription.text];
NSString *lEventCity = [NSString stringWithFormat:@"var=%@",eventCity.text];
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"title=%@&description=%@&city=%@",lEventTitle ,lEventDesc,lEventCity];
myRequestString = [myRequestString stringByReplacingOccurrencesOfString:@"var=" withString:@""];
NSLog(@"%@",myRequestString);
// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.xsysdevelopment.com/ios/form.php"]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);
if ([response rangeOfString:@"SUCCESSFUL"].location == NSNotFound)
{
//here??
}
}
感謝您的幫助提前
是否要提示消息結果? – 2013-03-24 16:04:39
是的,這將是非常好的。然後當用戶點擊確定...它加載另一個單獨的視圖,即主視圖。 – 2013-03-24 16:05:44