DetailTopicCell.m 5.3 KB

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