Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS应用程序中从MySQL加载数据_Ios_Mysql_Objective C - Fatal编程技术网

在iOS应用程序中从MySQL加载数据

在iOS应用程序中从MySQL加载数据,ios,mysql,objective-c,Ios,Mysql,Objective C,早上好 如何将MySQL查询结果加载到iOS应用程序的UILabel中?我需要显示用户的名字,追随者和个人资料图像。我该怎么做 我已经用UILabels和UIImageView创建了故事板,但是现在我需要从MySQL数据库加载数据,我有点迷路了 提前感谢。您可以使用JSON获取数据 NSMutableURLRequest * requestTransfer; NSString *strUrl = @"www.yoursite.com/Mobile/GetUser"; requestTransfe

早上好

如何将MySQL查询结果加载到iOS应用程序的UILabel中?我需要显示用户的名字,追随者和个人资料图像。我该怎么做

我已经用UILabels和UIImageView创建了故事板,但是现在我需要从MySQL数据库加载数据,我有点迷路了


提前感谢。

您可以使用JSON获取数据

NSMutableURLRequest * requestTransfer;
NSString *strUrl = @"www.yoursite.com/Mobile/GetUser";
requestTransfer = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:strUrl]
                                               cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
[requestTransfer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[requestTransfer setHTTPMethod:@"POST"];

NSHTTPURLResponse   * response;
NSError* error = nil;
response = nil;

NSData * data = [NSURLConnection sendSynchronousRequest:requestTransfer returningResponse:&response error:&error];
NSDictionary *dicUsers = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
你可以像那样使用字典

NSString* strID = [dictionary objectForKey:@"UserID"];
NSString* strName = [dictionary objectForKey:@"UserName"];
NSString* strLink = [dictionary objectForKey:@"ImageLink"];
yourlabel.text = strName;

谢谢优素福,你能给我举个例子吗?我知道一些PHP和MySQL,但我不是JSON和Xcode的专家。。。!例如:如何加载UILabel?该UILabel是来自我的数据库用户的一行中的一个单元格。非常感谢您的帮助。谢谢Yusuf,我将尝试使用您的代码。我唯一不明白的是,如何通过JSON发送MySQL查询,然后接收数据。。。!你能告诉我怎么做吗?我不懂php。www.yoursite.com/Mobile/GetUser u必须创建这样的链接,并且必须返回用户。这是一个例子,有人知道怎么做吗?因为我在这一点上迷路了,优素福。谢谢优素福,我要试试这个。