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. @implementation SliderPage
  10. - (id)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. // Initialization code
  15. }
  16. return self;
  17. }
  18. -(void) loadImage
  19. {
  20. if(self.image==nil)
  21. {
  22. NSString* file_name=[self.img_url lastPathComponent];
  23. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:self.img_url];
  24. if(img_data!=nil)
  25. {
  26. UIImage * img =[UIImage imageWithData:img_data];
  27. self.image = img;
  28. }
  29. else
  30. {
  31. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  32. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.img_url]];
  33. dispatch_async(dispatch_get_main_queue(), ^{
  34. if(downloadimg_data!=nil)
  35. {
  36. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:self.img_url];
  37. UIImage * img =[UIImage imageWithData:downloadimg_data];
  38. self.image = img;
  39. }
  40. });
  41. });
  42. }
  43. }
  44. }
  45. /*
  46. // Only override drawRect: if you perform custom drawing.
  47. // An empty implementation adversely affects performance during animation.
  48. - (void)drawRect:(CGRect)rect
  49. {
  50. // Drawing code
  51. }
  52. */
  53. @end