TableViewCell 里面嵌的TableViewCell 如何点击里面的TableViewCell进行页面跳转?
2016-12-29 14:35
459 查看
下面是里面TableView的代码
下面是主TableViewCell的代码
#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; } }
相关文章推荐
- 如何实现点击a标签当所要跳转的页面加载完成后在进行跳转
- 如何实现点击UITableViewCell中的控件,能调用到所在的ViewController对象进行页面跳转
- 如何在程序里面跳转到market上面的下载等其他页面。
- UIWebView中链接调用Safari打开目标链接 点击cell里面的一个按钮如何确定按钮所在的cell的行
- 如何点击链接直接跳转到app store指定应用下载页面
- 如何优雅的进行页面间的跳转
- 转:ECharts图表组件之简单关系图:如何轻松实现另类站点地图且扩展节点属性实现点击节点页面跳转
- SSH中点击jsp页面连接进行action跳转时出现无数窗口
- 如何实现点击一个按钮后跳转的指定的链接页面
- 在项目中,点击“删除”按钮后,跳转到哪个页面?又该如何设置?
- listview上进行ontouch事件,可滑动,可点击页面跳转
- 如何监控iframe里面页面的点击事件
- 如何在tableviewcell里面嵌入switch控件以及如何获取switch控件数据
- 如何用js实现,在一个页面有个输入文档框,然后点击查询按扭后,调用IE的查询功能在当前页面进行查询
- 在Datalist中通过点击某条目录跳转页面时用URL进行传值的方法
- 如何点击链接直接跳转到app store指定应用下载页面
- 如何点击链接直接跳转到app store指定应用下载页面
- gridview里面点击某一数据进行跳转
- 如何让链接为空 即点击时不进行跳转
- 如何绑定android点击事件--跳转到另一个页面并实现关闭功能?