0
我试图找到这个答案几天,现在找不到任何东西。我存储url在我的数据库中的图像,我试图得到这个URL并加载图像到ImageView。将MYSQL加载到Imageview的图像
用户上传图像,我的PHP脚本为数据库中的图像创建一个url。这是我的数据库表:ID - >用户名 - >密码 - > urlImage。我还有另一个PHP脚本,它接受urlImage的用户名和密码。
在Xcode中,我想补充一句:' NSUserDefaults * settings = [NSUserDefaults standardUserDefaults]; NSString * user = [设置valueForKey:@“用户名”];
NSString *post = [NSString stringWithFormat:@"username=%@&image=dummy",user];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://url.com/Wish_Profile_Pic.php"]];
NSString *postLen = [[NSString alloc] initWithFormat:@"%d" ,[post length ]];
[request setValue:postLen forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
//this is hard coded based on your suggested values, obviously you'd probably need to make this more dynamic based on your application's specific data to send
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
`
这将发送一个请求到数据库服务器和服务器将输出urlImage。我如何在ImageView中查看图像?无法找到任何关于此。
我会尝试这个权利了,但看起来像是我需要:) – user2351814 2013-05-11 14:27:36
这样做后异步,当它回来,你从响应数据 – 2013-05-11 14:28:01
获取图像我在viewDidLoad中尝试这样做,不得不将此行更改为self> imageView.image = img;但没有看到我的imageview中的任何东西。你有一个教程或什么?或者你是怎么跟这个去的?它应该只是简单的做一个IBOutlet UIImageView * imageView在.h和你的代码在.m的权利? – user2351814 2013-05-11 14:45:34