UICollection从url查看图像

时间:2013-02-20 21:06:04

标签: objective-c url ios6 uicollectionview

我已按照本教程制作UICollectionView自定义布局:http://skeuo.com/uicollectionview-custom-layout-tutorial#section4 我完成了它,我得到了它的工作。但是,当我尝试将它与我自己的照片一起使用时,我无法在应用程序中显示它们。 这是获取图片的代码

     self.albums = [NSMutableArray array];

    NSURL *urlPrefix =
        [NSURL URLWithString:@"https://raw.github.com/ShadoFlameX/PhotoCollectionView/master/Photos/"];

    NSInteger photoIndex = 0;

    for (NSInteger a = 0; a < 12; a++) {
        BHAlbum *album = [[BHAlbum alloc] init];
        album.name = [NSString stringWithFormat:@"Photo Album %d",a + 1];

        NSUInteger photoCount = 1;
        for (NSInteger p = 0; p < photoCount; p++) {
            // there are up to 25 photos available to load from the code repository
            NSString *photoFilename = [NSString stringWithFormat:@"thumbnail%d.jpg",photoIndex % 25];
            NSURL *photoURL = [urlPrefix URLByAppendingPathComponent:photoFilename];
            BHPhoto *photo = [BHPhoto photoWithImageURL:photoURL];
            [album addPhoto:photo];

            photoIndex++;
        }

    [self.albums addObject:album];
}

所以当我将url字符串更改为带有我的图片的字符串时,问题就出现了。我想使用一个公共网站来托管像Flickr这样的图像,但我也尝试过Imageshak.us和postimage.org但它没有用。 我有照片名称,因为它说的字符串:thumbnail%d.jpd所以这不是问题。有什么想法吗?

更新: 我试过用这个

[NSURL URLWithString:@"http://www.flickr.com/photos/93436974@N06/"];

这是画廊的网址,但它没有显示任何内容。如果我不能使用Flickr,是否有其他类似的网站可以使用?

1 个答案:

答案 0 :(得分:2)

对于你的缩略图,你将它们命名为“thumbnail0.jpg”“thumbnail1.jpg”等对吗? %d表示在此处插入引号外部的数字,因为您发布的代码需要您使用的任何数字照片并将其添加到您的字符串中(最多25个,此时它将重新启动,即照片27会返回thumbnail2.jpg

快速谷歌搜索它看起来像flickr不保留源文件名,所以它不适用于您发布的代码。我建议使用photobucket我知道他们保留了源文件名,并且网址很容易使用

相关问题