DetailTopicCell.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  61. NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
  62. if(value==nil)
  63. value=@"";
  64. unsigned long color = strtoul([value UTF8String],0,16);
  65. static NSString * CellIdentifier = @"RelatedModelCell";
  66. CategoryCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  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. if (!appDelegate.offline_mode) {
  90. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  91. }
  92. dispatch_async(dispatch_get_main_queue(), ^{
  93. if(downloadimg_data!=nil)
  94. {
  95. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  96. UIImage * img =[UIImage imageWithData:downloadimg_data];
  97. cell.cellImageView.image = img;
  98. }
  99. else
  100. cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  101. });
  102. });
  103. }
  104. }
  105. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  106. cell.layer.borderWidth = 0.5;
  107. //cell.layer.cornerRadius=15;
  108. cell.layer.masksToBounds=true;
  109. return cell;
  110. }
  111. #pragma mark --UICollectionViewDelegateFlowLayout
  112. ////定义每个UICollectionView 的大小
  113. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  114. //{
  115. // return CGSizeMake(96, 100);
  116. //}
  117. //定义每个UICollectionView 的 margin
  118. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  119. {
  120. return UIEdgeInsetsMake(10, 10, 10, 10);
  121. }
  122. #pragma mark --UICollectionViewDelegate
  123. //UICollectionView被选中时调用的方法
  124. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  125. {
  126. NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  127. NSString* product_id = [json valueForKey:@"product_id"];
  128. NSString* category = [json valueForKey:@"category"];
  129. [itemdelegate TopicItemClicked : product_id category:category];
  130. }
  131. @end