Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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/9/ios/105.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/1/oracle/10.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
Iphone 从php文件获取图像到iOS_Iphone_Ios_Ios5_Ios6 - Fatal编程技术网

Iphone 从php文件获取图像到iOS

Iphone 从php文件获取图像到iOS,iphone,ios,ios5,ios6,Iphone,Ios,Ios5,Ios6,我想通过用户id从特定用户的php文件(例如:)中获取图像,并在iOS应用程序的图像视图中设置图像。我怎样才能做到? 提前感谢。您可以从上述URL以NSData的形式获取图像: NSData *imageData = [NSData dataWithContentsOfURL:[NSURL urlWithString:@"http://abc.xyz.com/api/showImage.php"]]; UIImageView *imageView = [UIImageView alloc] in

我想通过用户id从特定用户的php文件(例如:)中获取图像,并在iOS应用程序的图像视图中设置图像。我怎样才能做到?
提前感谢。

您可以从上述URL以NSData的形式获取图像:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL urlWithString:@"http://abc.xyz.com/api/showImage.php"]];
UIImageView *imageView = [UIImageView alloc] initWithImage:[UIImage imageWithData:imageData]];

您可以从上述URL以NSData的形式获取图像:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL urlWithString:@"http://abc.xyz.com/api/showImage.php"]];
UIImageView *imageView = [UIImageView alloc] initWithImage:[UIImage imageWithData:imageData]];

在显示来自web的图像时,最好使用Asyn下载方法。
您可以在UIImageView上创建自己的类别,也可以使用流行的类别


在显示来自web的图像时,最好使用Asyn下载方法。
您可以在UIImageView上创建自己的类别,也可以使用流行的类别


将响应存储到数组中,然后存储到对象(比如profile对象)中。我正在使用
SDWebImage
。 如果您在
detailsObj.profileImage
处获取图像url,请使用下面的方法设置为
imageview

 NSLog(@"response is:%@",userDetailsArray);


ProfileObject *detailsObj=[userDetailsArray objectAtIndex:0];
//使用获取图像的url服务器链接代替detailsObj.profileImage

if([detailsObj.profileImage isEqualToString:@""] || [detailsObj.profileImage isKindOfClass:[NSNull class]] || detailsObj.profileImage.length==0)

{

    self.profileImageView.image=[UIImage imageNamed:@"NoImage.png"];
}

else

{
//不使用SDWebImage

[self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage]];
 [self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage] placeholderImage:[UIImage imageNamed:@"NoImage.png"]];

}
//如果是从服务器获取数据

self.profileImageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL urlWithString:detailsObj.profileImage]]];
//或者使用SDWebImage

[self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage]];
 [self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage] placeholderImage:[UIImage imageNamed:@"NoImage.png"]];

}

将响应存储到数组中,然后存储到对象(比如profile对象)中。我正在使用
SDWebImage
。 如果您在
detailsObj.profileImage
处获取图像url,请使用下面的方法设置为
imageview

 NSLog(@"response is:%@",userDetailsArray);


ProfileObject *detailsObj=[userDetailsArray objectAtIndex:0];
//使用获取图像的url服务器链接代替detailsObj.profileImage

if([detailsObj.profileImage isEqualToString:@""] || [detailsObj.profileImage isKindOfClass:[NSNull class]] || detailsObj.profileImage.length==0)

{

    self.profileImageView.image=[UIImage imageNamed:@"NoImage.png"];
}

else

{
//不使用SDWebImage

[self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage]];
 [self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage] placeholderImage:[UIImage imageNamed:@"NoImage.png"]];

}
//如果是从服务器获取数据

self.profileImageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL urlWithString:detailsObj.profileImage]]];
//或者使用SDWebImage

[self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage]];
 [self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage] placeholderImage:[UIImage imageNamed:@"NoImage.png"]];

}

不行,兄弟。不确定问题是否为用户id!当我们点击那个URL时,你们能告诉我你们的服务器正在返回什么吗?服务器正在返回二进制数据。你们能检查imageData是否为空吗?如果是,那么你的服务器的问题,否则你可以使用SDWebImage。它不工作,兄弟。不确定问题是否为用户id!当我们点击那个URL时,你们能告诉我你们的服务器正在返回什么吗?服务器正在返回二进制数据。你们能检查imageData是否为空吗?如果是,则说明服务器存在问题,否则可以使用SDWebImage。