我是iOS编程新手。我正在从服务器获取图像和音频文件。之后,使用下面的代码,我试图将所有图像显示为缩略图。有谁能告诉我怎样才能把所有的图片显示为缩略图吗?也没有播放音频。
-(IBAction)fullsizeimage:(id)sender
{
////////////// Image ////////////////////////////
NSURL *url = [NSURL URLWithString:@"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/thumbnail_small/326.png"];
NSData *data = [NSData dataWithContentsOfURL: url];
UIImage *image = [UIImage imageWithData:data];
imagee = [[UIImageView alloc] initWithImage: image];
[self.view addSubview:imagee];
NSURL *url1 = [NSURL URLWithString:@"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/thumbnail_small/327.png"];
NSData *data1 = [NSData dataWithContentsOfURL: url1];
UIImage *image1 = [UIImage imageWithData:data1];
imagee1 = [[UIImageView alloc] initWithImage: image1];
[self.view addSubview:imagee1];
NSURL *urll = [NSURL URLWithString:@"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/thumbnail_small/325.png"];
NSData *dataa = [NSData dataWithContentsOfURL: urll];
UIImage *imageee = [UIImage imageWithData:dataa];
imagee2 = [[UIImageView alloc] initWithImage: imageee];
[self.view addSubview:imagee2];
/////////////// Audio ///////////////////////
NSURL *audiourl = [NSURL URLWithString:@"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/Audio/312.mp3"];
NSData *audioData = [NSData dataWithContentsOfURL:audiourl];
NSError *error;
//AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioData error:&error];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:audioData error:&error];
audioPlayer.numberOfLoops = -1;
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
}
谢谢Aslam
考虑在将每个图像添加到superview
之前为它们分配不同的帧。您的代码可能会为每个图像分配相同的帧。
使用NSLog(@"%@", [self.view subviews]);
来了解图像视图是否存在并已加载
在你的主视图上设置不同的UIImageView(带有你需要的缩略图框架),然后在上面添加这些图像
你可以考虑使用moriarty库中的GridView,或者在UIScrollView中作为一个大网格,或者在UITableView中以更高效的逐行方式使用。
你可以从Three20项目,它可以作为iOS内置的相机卷来查看图像