我们正在尝试修改 iphone 文本字段中的数据,然后将(数据)返回到服务器中的 mysql 数据库。
我们有几个问题:
ASIFormDataRequest 是用于此目的的首选工具吗?如果没有,你能推荐一个并解释如何合并吗?如果 ASIFormDataRequest 是正确的工具,我们如何以及在哪里将 ASIFormDataRequest 合并到 Xcode 和 PHP 中?
以下是包含我们编写的代码的三个文件,我们欢迎您的所有见解。谢谢你的慷慨!
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController {
NSDictionary *newsArticle;
IBOutlet UILabel *titleLabel;
IBOutlet UILabel *timeLabel;
IBOutlet UITextField *fieldname;
IBOutlet UITextField *fieldtitle;
IBOutlet UITextField *fielddate;}
@property (nonatomic, copy) NSDictionary *newsArticle;
@end
细节视图控制器.m
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize newsArticle;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
titleLabel.text = [newsArticle objectForKey:@"name"];
timeLabel.text = [newsArticle objectForKey:@"title"];
fieldname.text = [newsArticle objectForKey:@"name"];
fieldtitle.text = [newsArticle objectForKey:@"title"];
fielddate.text = [newsArticle objectForKey:@"date"];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
php文件
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
$query = mysql_query("SELECT * FROM afitest");
$arr = array();
while($row = mysql_fetch_assoc($query)) {
$arr[] = $row;
}
echo json_encode($arr);
?>