TopicViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // TopicViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-5-26.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "MainViewController.h"
  9. #import "TopicViewController.h"
  10. @interface TopicViewController ()
  11. @end
  12. @implementation TopicViewController
  13. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  14. {
  15. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  16. if (self) {
  17. // Custom initialization
  18. }
  19. return self;
  20. }
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. CGRect r= self.TopicCollection.frame;
  25. r.size.height = self.count/4 * 210;
  26. self.TopicCollection.frame = r;
  27. // UICollectionView* TopicCollectiondelegate =self.TopicCollection;
  28. self.TopicCollection.delegate = self;
  29. // Do any additional setup after loading the view.
  30. }
  31. - (void)didReceiveMemoryWarning
  32. {
  33. [super didReceiveMemoryWarning];
  34. // Dispose of any resources that can be recreated.
  35. }
  36. -(void) itemCount : (int)count
  37. {
  38. self.count = count;
  39. }
  40. /*
  41. #pragma mark - Navigation
  42. // In a storyboard-based application, you will often want to do a little preparation before navigation
  43. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  44. {
  45. // Get the new view controller using [segue destinationViewController].
  46. // Pass the selected object to the new view controller.
  47. }
  48. */
  49. #pragma mark -- UICollectionViewDataSource
  50. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  51. {
  52. // 每个Section的item个数
  53. return self.count;
  54. }
  55. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  56. {
  57. return 1;
  58. }
  59. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. static NSString * CellIdentifier = @"TopicItem";
  62. TopCellItem * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  63. NSDictionary * item_json =[self.content objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row] ];
  64. NSString* img_url =[item_json valueForKey:@"img"];
  65. NSString* description =[item_json valueForKey:@"description"];
  66. NSString* old_price =[item_json valueForKey:@"old_price"];
  67. NSString* price =[item_json valueForKey:@"price"];
  68. cell.cellDescription.text = description;
  69. cell.oldPrice.text = old_price;
  70. cell.Price.text = price;
  71. cell.cellImage.image=[UIImage imageNamed:@"loading_s"];
  72. NSString* file_name=[img_url lastPathComponent];
  73. NSData* img_data=[iSalesDB load_cached_img:file_name];
  74. if(img_data!=nil)
  75. {
  76. UIImage * img =[UIImage imageWithData:img_data];
  77. cell.cellImage.image = img;
  78. }
  79. else
  80. {
  81. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  82. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  83. dispatch_async(dispatch_get_main_queue(), ^{
  84. if(downloadimg_data!=nil)
  85. {
  86. [iSalesDB cache_img:downloadimg_data :file_name ];
  87. UIImage * img =[UIImage imageWithData:downloadimg_data];
  88. cell.cellImage.image = img;
  89. }
  90. else
  91. cell.cellImage.image=[UIImage imageNamed:@"notfound_s"];
  92. });
  93. });
  94. }
  95. // cell.backgroundColor = [UIColor colorWithRed:((10 * indexPath.row) / 255.0) green:((20 * indexPath.row)/255.0) blue:((30 * indexPath.row)/255.0) alpha:1.0f];
  96. return cell;
  97. }
  98. //#pragma mark --UICollectionViewDelegateFlowLayout
  99. ////定义每个UICollectionView 的大小
  100. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  101. //{
  102. // return CGSizeMake(96, 100);
  103. //}
  104. //定义每个UICollectionView 的 margin
  105. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  106. {
  107. return UIEdgeInsetsMake(5, 5, 5, 5);
  108. }
  109. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. int type = 0;
  112. // if(collectionView == self.topicview.TopicCollection)
  113. // type = 0;
  114. // else
  115. // type = 1;
  116. MainViewController* pvc = (MainViewController*)self.rootViewController;
  117. [pvc topicViewSelected:type _id:(int)indexPath.row];
  118. // [(MainViewController*)self.parentViewController topicViewSelected type:indexPath.row];
  119. }
  120. //- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  121. //{
  122. // // CGRect frame = self.view.frame;
  123. // // [self.carouselController.view removeFromSuperview];
  124. // // wait(2000);
  125. // // self.carouselController = [[FPCarouselNonXIBViewController alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 400)];
  126. // // [self.view addSubview:self.carouselController.view];
  127. // // int i = self.view.subviews.count;
  128. // // int b = 0;
  129. // // [self.carouselController updateFrame:CGRectMake(0, 0, self.view.frame.size.width, 400)];
  130. //}
  131. ////返回这个UICollectionView是否可以被选择
  132. //-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
  133. //{
  134. // return YES;
  135. //}
  136. @end