DetailTopicCell.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
  74. NSString* file_name=[img_url lastPathComponent];
  75. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  76. if(img_data!=nil)
  77. {
  78. UIImage * img =[UIImage imageWithData:img_data];
  79. cell.cellImageView.image = img;
  80. }
  81. else
  82. {
  83. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  84. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  85. dispatch_async(dispatch_get_main_queue(), ^{
  86. if(downloadimg_data!=nil)
  87. {
  88. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  89. UIImage * img =[UIImage imageWithData:downloadimg_data];
  90. cell.cellImageView.image = img;
  91. }
  92. else
  93. cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  94. });
  95. });
  96. }
  97. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  98. cell.layer.borderWidth = 0.5;
  99. //cell.layer.cornerRadius=15;
  100. cell.layer.masksToBounds=true;
  101. return cell;
  102. }
  103. #pragma mark --UICollectionViewDelegateFlowLayout
  104. ////定义每个UICollectionView 的大小
  105. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  106. //{
  107. // return CGSizeMake(96, 100);
  108. //}
  109. //定义每个UICollectionView 的 margin
  110. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  111. {
  112. return UIEdgeInsetsMake(10, 10, 10, 10);
  113. }
  114. #pragma mark --UICollectionViewDelegate
  115. //UICollectionView被选中时调用的方法
  116. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  117. {
  118. NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  119. NSString* product_id = [json valueForKey:@"product_id"];
  120. NSString* category = [json valueForKey:@"category"];
  121. [itemdelegate TopicItemClicked : product_id category:category];
  122. }
  123. @end