DetailTopicCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // DetailRelatedCell.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-7-31.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailTopicCell.h"
  9. #import "CategoryCellSmall.h"
  10. #import "iSalesDB.h"
  11. #import "DetailViewController.h"
  12. #import "DefaultAppearance.h"
  13. #import "AppDelegate.h"
  14. @implementation DetailTopicCell
  15. @synthesize itemdelegate;
  16. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  17. {
  18. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  19. if (self) {
  20. // Initialization code
  21. }
  22. return self;
  23. }
  24. - (void)awakeFromNib
  25. {
  26. // Initialization code
  27. self.refreshLabel.layer.borderColor = [UIColor darkGrayColor].CGColor;
  28. self.refreshLabel.layer.borderWidth = 2.0;
  29. self.refreshLabel.layer.cornerRadius=15;
  30. self.refreshLabel.layer.masksToBounds=true;
  31. }
  32. -(void) begin_refresh
  33. {
  34. self.topicCollectionView.hidden=true;
  35. self.refreshLabel.hidden=false;
  36. }
  37. -(void) end_refresh
  38. {
  39. self.topicCollectionView.hidden=false;
  40. self.refreshLabel.hidden=true;
  41. }
  42. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  43. {
  44. [super setSelected:selected animated:animated];
  45. // Configure the view for the selected state
  46. }
  47. #pragma mark -- UICollectionViewDataSource
  48. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  49. {
  50. // 每个Section的item个数
  51. int count =[[self.related_data valueForKey:@"count"] intValue];
  52. return count;
  53. }
  54. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  55. {
  56. return 1;
  57. }
  58. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
  61. if(value==nil)
  62. value=@"";
  63. unsigned long color = strtoul([value UTF8String],0,16);
  64. static NSString * CellIdentifier = @"RelatedModelCell";
  65. CategoryCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  66. cell.cellImageView.contentMode = UIViewContentModeScaleAspectFit;
  67. NSDictionary * item_json =[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  68. NSString* img_url =[item_json valueForKey:@"picture_path"];
  69. NSString* description =[item_json valueForKey:@"fash_name"];
  70. // NSString* old_price =[item_json valueForKey:@"old_price"];
  71. // NSString* price =[item_json valueForKey:@"price"];
  72. cell.cellDescription.text = description;
  73. // cell.oldPrice.text = old_price;
  74. // cell.Price.text = price;
  75. if (![cell.imageName isEqualToString:img_url]) {
  76. cell.imageName = img_url;
  77. cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
  78. NSString* file_name=[img_url lastPathComponent];
  79. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  80. if(img_data!=nil)
  81. {
  82. UIImage * img =[UIImage imageWithData:img_data];
  83. cell.cellImageView.image = img;
  84. }
  85. else
  86. {
  87. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  88. NSData* downloadimg_data = nil;
  89. BOOL offline = NO;
  90. #ifdef OFFLINE_MODE
  91. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  92. offline = appDelegate.offline_mode;
  93. #endif
  94. if (!offline) {
  95. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  96. }
  97. dispatch_async(dispatch_get_main_queue(), ^{
  98. if(downloadimg_data!=nil)
  99. {
  100. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  101. UIImage * img =[UIImage imageWithData:downloadimg_data];
  102. cell.cellImageView.image = img;
  103. }
  104. else
  105. cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  106. });
  107. });
  108. }
  109. }
  110. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  111. cell.layer.borderWidth = 0.5;
  112. //cell.layer.cornerRadius=15;
  113. cell.layer.masksToBounds=true;
  114. return cell;
  115. }
  116. #pragma mark --UICollectionViewDelegateFlowLayout
  117. ////定义每个UICollectionView 的大小
  118. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  119. //{
  120. // return CGSizeMake(96, 100);
  121. //}
  122. //定义每个UICollectionView 的 margin
  123. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  124. {
  125. return UIEdgeInsetsMake(10, 10, 10, 10);
  126. }
  127. #pragma mark --UICollectionViewDelegate
  128. //UICollectionView被选中时调用的方法
  129. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  130. {
  131. NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  132. NSString* product_id = [json valueForKey:@"product_id"];
  133. NSString* category = [json valueForKey:@"category"];
  134. [itemdelegate TopicItemClicked : product_id category:category];
  135. }
  136. @end