DetailTopicCell.m 4.7 KB

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