【问题标题】:iOS : Create dynamic URL for KTPhotoBrowserDataSourceiOS:为 KTPhotoBrowserDataSource 创建动态 URL
【发布时间】:2012-01-06 13:23:48
【问题描述】:

我正在使用这个API 为我的应用程序创建一个在线图片库,但问题是我需要创建一个动态画廊这个示例代码中的代码仅显示来自 flickr 的一些图像,我需要显示来自 URL 的图像这里是代码:

例如:www.mysite.com/gallery

而且这个网址上有很多照片!

- (id)init {
   self = [super init];
   if (self) {
      // Create a 2-dimensional array. First element of
      // the sub-array is the full size image URL and 
      // the second element is the thumbnail URL.
      images_ = [[NSArray alloc] initWithObjects:

                 [NSArray arrayWithObjects:@"http://farm5.static.flickr.com/4001/4439826859_19ba9a6cfa_o.jpg", @"http://farm5.static.flickr.com/4001/4439826859_4215c01a16_s.jpg", nil],

                 [NSArray arrayWithObjects:@"http://farm4.static.flickr.com/3427/3192205971_0f494a3da2_o.jpg", @"http://http://farm4.static.flickr.com/3427/3192205971_0f494a3da2_o.jpg" , nil];
   }
   return self;
}

#pragma mark -
#pragma mark KTPhotoBrowserDataSource

- (NSInteger)numberOfPhotos {
   NSInteger count = [images_ count];
   return count;
}

- (void)imageAtIndex:(NSInteger)index photoView:(KTPhotoView *)photoView {
   NSArray *imageUrls = [images_ objectAtIndex:index];
   NSString *url = [imageUrls objectAtIndex:FULL_SIZE_INDEX];
   [photoView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"photoDefault.png"]];
}

- (void)thumbImageAtIndex:(NSInteger)index thumbView:(KTThumbView *)thumbView {
   NSArray *imageUrls = [images_ objectAtIndex:index];
   NSString *url = [imageUrls objectAtIndex:THUMBNAIL_INDEX];
   [thumbView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"photoDefault.png"]];
} 

【问题讨论】:

  • 看起来您在此处丢失了问题的结尾。此外,这应该在 SO 而不是这里。投票结束它,但如果你完成了这个问题,也许一个不错的 mod 会为你转移问题。
  • 对不起“但是”是我的错误,我删除了

标签: iphone ios ipad xcode sdk


【解决方案1】:

画廊网站返回 json 还是 xml?如果没有,那么您需要读取从画廊网站返回的 HTML 并检索图像标签。您可以使用http://github.com/topfunky/hpple/tree/masterhttp://github.com/zootreeves/Objective-C-HMTL-Parser 来解析HTML。对于简单的 HTML,这种方法应该可以工作。

如果 HTML 很复杂,则使用画廊网站YQL to scrape 并转换为 JSON。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-09
    • 2011-10-01
    • 1970-01-01
    • 2019-04-25
    • 2018-11-22
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多