| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // DetailRelatedCell.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-7-31.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "DetailTopicCell.h"
- #import "CategoryCellSmall.h"
- #import "iSalesDB.h"
- #import "DetailViewController.h"
- #import "DefaultAppearance.h"
- @implementation DetailTopicCell
- @synthesize itemdelegate;
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (void)awakeFromNib
- {
- // Initialization code
-
- self.refreshLabel.layer.borderColor = [UIColor darkGrayColor].CGColor;
- self.refreshLabel.layer.borderWidth = 2.0;
- self.refreshLabel.layer.cornerRadius=15;
- self.refreshLabel.layer.masksToBounds=true;
- }
- -(void) begin_refresh
- {
- self.topicCollectionView.hidden=true;
- self.refreshLabel.hidden=false;
-
- }
- -(void) end_refresh
- {
- self.topicCollectionView.hidden=false;
- self.refreshLabel.hidden=true;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- #pragma mark -- UICollectionViewDataSource
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
-
- // 每个Section的item个数
- int count =[[self.related_data valueForKey:@"count"] intValue];
- return count;
-
- }
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
- NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
-
-
-
-
-
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
- static NSString * CellIdentifier = @"RelatedModelCell";
- CategoryCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary * item_json =[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString* img_url =[item_json valueForKey:@"picture_path"];
- NSString* description =[item_json valueForKey:@"fash_name"];
- // NSString* old_price =[item_json valueForKey:@"old_price"];
- // NSString* price =[item_json valueForKey:@"price"];
- cell.cellDescription.text = description;
- // cell.oldPrice.text = old_price;
- // cell.Price.text = price;
- cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.cellImageView.image = img;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.cellImageView.image = img;
- }
- else
- cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
-
- });
- });
-
-
- }
-
-
- cell.layer.borderColor = UIColorFromRGB(color).CGColor;
- cell.layer.borderWidth = 0.5;
- //cell.layer.cornerRadius=15;
- cell.layer.masksToBounds=true;
- return cell;
-
- }
- #pragma mark --UICollectionViewDelegateFlowLayout
- ////定义每个UICollectionView 的大小
- //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- //{
- // return CGSizeMake(96, 100);
- //}
- //定义每个UICollectionView 的 margin
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(10, 10, 10, 10);
- }
- #pragma mark --UICollectionViewDelegate
- //UICollectionView被选中时调用的方法
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString* product_id = [json valueForKey:@"product_id"];
- NSString* category = [json valueForKey:@"category"];
- [itemdelegate TopicItemClicked : product_id category:category];
- }
- @end
|