下面是里面TableView的代码
#import "ClassViewCell.h"
#import "MyCollectionCell.h"
#import "StringManager.h"
#import "HomeViewController.h"
#import "FreeWorkList.h"
@implementation ClassViewCell
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
@synthesize names;
@synthesize images;
- (void)awakeFromNib {
// Initialization code
[self setUpCollection];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setUpCollection{
UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 200) collectionViewLayout:flowLayout];
self.collectionView.dataSource=self;
self.collectionView.delegate=self;
[self.collectionView setBackgroundColor:[UIColor clearColor]];
names=@[@"兼职",@"培训",@"活动",@"实习",@"全职",@"假期工",@"在线兼职",@"公告"];
images=@[@"jzicon.png",@"pxicon.png",@"hdicon.png",@"sxicon.png",@"qzicon.png",@"jqgicon.png",@"zxjzicon.png",@"ggicon.png"];
}
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 8;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"MyCollectionCell";
UINib *cellNib = [UINib nibWithNibName:@"MyCollectionCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"MyCollectionCell"];
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
UILabel *label = (UILabel *)[cell viewWithTag:2];
UIImageView *imageVIew=(UIImageView *)[cell viewWithTag:1];
label.text=[names objectAtIndex:indexPath.row];
imageVIew.image=[UIImage imageNamed:[images objectAtIndex:indexPath.row]];
return cell;
}
#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个Item 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(70, 70);
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if([[StringManager deviceString] isEqualToString:@"iPhone6"])
{
return UIEdgeInsetsMake(0, 30, 5, 20);
}
else if ([[StringManager deviceString] isEqualToString:@"iPhone6Plus"])
{
return UIEdgeInsetsMake(0, 30, 5, 20);
}
else
{
return UIEdgeInsetsMake(0, 10, 0, 0);
}
}
#pragma mark --UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
//临时改变个颜色,看好,只是临时改变的。如果要永久改变,可以先改数据源,然后在cellForItemAtIndexPath中控制。(和UITableView差不多吧!O(∩_∩)O~)
cell.backgroundColor = [UIColor clearColor];
NSLog(@"走到这里了");
}
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
@end
下面是主TableViewCell的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==0){
//NSLog(@"cellForRowAtIndexPath:%@",tmpStr2);
UINib *cellNib = [UINib nibWithNibName:@"ClassViewCell" bundle:nil];
[self.tbView registerNib:cellNib forCellReuseIdentifier:@"ClassViewCell"];
TableViewCell *scell = [self.tbView dequeueReusableCellWithIdentifier:@"ClassViewCell"];
scell.contentView.backgroundColor = [UIColor clearColor];
UIView *backgroundView = [[UIView alloc] initWithFrame:scell.frame];
backgroundView.backgroundColor = [UIColor clearColor];
scell.selectedBackgroundView = backgroundView;
return scell;
}else if(indexPath.row==1){
UINib *cellNib = [UINib nibWithNibName:@"InfoTableViewCell" bundle:nil];
[self.tbView registerNib:cellNib forCellReuseIdentifier:@"InfoTableViewCell"];
TableViewCell *scell = [self.tbView dequeueReusableCellWithIdentifier:@"InfoTableViewCell"];
UIView *backgroundView = [[UIView alloc] initWithFrame:scell.frame];
backgroundView.backgroundColor = [UIColor clearColor];
scell.selectedBackgroundView = backgroundView;
scell.backgroundColor=[UIColor clearColor];
return scell;
}else{
static NSString *CellTableIndentifer=@"TableViewcell";
UINib *cellNib = [UINib nibWithNibName:@"TableViewCell" bundle:nil];
[self.tbView registerNib:cellNib forCellReuseIdentifier:@"TableViewCell"];
TableViewCell *scell = [self.tbView dequeueReusableCellWithIdentifier:@"TableViewCell"];
UIView *backgroundView = [[UIView alloc] initWithFrame:scell.frame];
backgroundView.backgroundColor = SELECTED_BACKGROUND;
scell.selectedBackgroundView = backgroundView;
if(fwids.count>=8)
{
scell.title=[fwnames objectAtIndex:indexPath.row-2];
scell.content=[fwcons objectAtIndex:indexPath.row-2];
scell.content2=[fwcon2s objectAtIndex:indexPath.row-2];
scell.money=[fwmoneys objectAtIndex:indexPath.row-2];
scell.city=[fwcitys objectAtIndex:indexPath.row-2];
scell.iconsrc=[UIImage imageNamed:[images objectAtIndex:indexPath.row-2]];
}
return scell;
}
}