SliderPage.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // SliderPage.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-30.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SliderPage.h"
  9. #import "FileCache.h"
  10. @implementation SliderPage
  11. - (id)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. // Initialization code
  16. }
  17. return self;
  18. }
  19. -(void) loadImage
  20. {
  21. if(self.image==nil)
  22. {
  23. NSString* file_name=[self.img_url lastPathComponent];
  24. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:self.img_url];
  25. if(img_data!=nil)
  26. {
  27. UIImage * img =[UIImage imageWithData:img_data];
  28. self.image = img;
  29. }
  30. else
  31. {
  32. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  33. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.img_url]];
  34. dispatch_async(dispatch_get_main_queue(), ^{
  35. if(downloadimg_data!=nil)
  36. {
  37. [FileCache cache_img:downloadimg_data filename:file_name saveTo:self.img_url];
  38. UIImage * img =[UIImage imageWithData:downloadimg_data];
  39. self.image = img;
  40. }
  41. });
  42. });
  43. }
  44. }
  45. }
  46. /*
  47. // Only override drawRect: if you perform custom drawing.
  48. // An empty implementation adversely affects performance during animation.
  49. - (void)drawRect:(CGRect)rect
  50. {
  51. // Drawing code
  52. }
  53. */
  54. @end