DetailTopicCell.m 4.3 KB

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