1. 程式人生 > >TableViewCell 裡面嵌的TableViewCell 如何點選裡面的TableViewCell進行頁面跳轉?

TableViewCell 裡面嵌的TableViewCell 如何點選裡面的TableViewCell進行頁面跳轉?

下面是裡面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]];
  
    
    
    
[email protected]
[@"兼職",@"培訓",@"活動",@"實習",@"全職",@"假期工",@"線上兼職",@"公告"];
    [email protected][@"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 *
[email protected]
"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;
    }
    
    
}


相關推薦

MUI click事件/新頁面問題

第一次接觸mui,談一下剛遇到的一些小問題咯。 第一步:引入應對的css\js <link href="css/mui.min.css" rel="stylesheet" /> <script src="js/mui.min.js"></sc

TableViewCell 裡面TableViewCell 如何裡面的TableViewCell進行頁面

下面是裡面TableView的程式碼 #import "ClassViewCell.h" #import "MyCollectionCell.h" #import "StringManager.h" #import "HomeViewController.h" #impor

1.angular html+css+js導航條樣式修改,加頁面

 1.html頁面程式碼如下: <div class="main-menu" id="L1" (click)="Tab(1)" style="color:#3bb9e2;"> 主頁 </div> <div class="main-menu

外部瀏覽器的按鈕到微信開啟網站url

跟大家交流技術 使用weixin://可以直接喚起微信,現在很多老鐵們都希望還要在微信中開啟自己的網站,沒有什麼功能是我們程式猿做不出來的,我自己也做了一套這樣的功能,你們看看我寫的程式碼怎樣,我本人是用php+mysql寫的,搭配資料庫環境就可以了。 php

小程式嵌入web-view網頁後,網頁中的按鈕回小程式

1.首先在網頁端引入js <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.0.js"&

element-UI實現分頁器切換頁碼後,某行就行,希望返回後,頁碼還是保持在剛才瀏覽的位置

如上圖所示的操作,使用element-UI的el-pagination外掛來做分頁。核心程式碼如下 <el-pagination @current-change="nextPage" layout="prev, pager, next"

Android使用ListView構造複雜介面,響應事件,通過Intentactivity

友情連結 vrix的部落格http://blog.csdn.net/vrix/article/details/5953710 雨鬆MOMO的程式世界專欄http://blog.csdn.net/xys289187120?viewmode=list

easyui-datagrid下一頁直接到最後一頁的可能原因

今天接到一個bug:初次進入頁面easyui-datagrid加載出第一頁的資料,點選下一頁的時候不是到第二頁而是到最後一頁。 如下圖所示:   這個bug確實讓我很鬱悶,最初以為是後臺的問題,除錯了一會兒發現跟後臺沒關係。 隨後檢查了下js程式碼,我的datagrid js

Android studio 按鈕開啟介面 (介面)

1,建立layout(activity_test.xml)在src/main/res/layout滑鼠右鍵new->LayoutResource File然後輸入一個file name,比如:activity_test點ok鍵完成建立2,建立activity(TestA

標籤的3個頁面練習頁面

<!DOCTYPE HTML> <html> <head> <title>錨點標籤的練習頁面</title> <meta charset="utf-8"/> <meta keywor

iframe 中某頁面的一個按鈕實現到iframe外面的窗體裡面

Default.aspx protected void Page_Load(object sender, EventArgs e) { Response.Redirect("WebForm1.aspx"); }

html裡面a標籤時去除下劃線

html程式碼: <a href="#">這裡是A標籤</a> CSS樣式: a:link{text-decoration:none; }  /* 指正常的未被訪問過的連結*/ a:visited{text-decoration:none; }

element-ui 裡面的按鈕以後會有提交的一個的載入中的標誌出現在button的字旁邊

點選前 點選後 <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登入</el-button

解決Listview的item和裡面控制元件事件衝突

兩種辦法1.設定裡面控制元件的focusable為false <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_p

裡面div或外面div的事件冒泡問題

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div style="width: 400px;he

jquery實現按鈕返回到頁面頂部效果

有的時候我們需要實現點選按鈕回到頁面頂部的效果,下面就是我的實現 首先HTML程式碼如下 <div class="QZ-up" style="display: none;"></div> 當滾動條高度大於120px的時候出現按鈕如下

React實現Echarts 當前內容進行匹配

onChartClick = (e) => { let ip = e.name; const obj = this.state.haviorData.find((e) => { return e.key === ip; }); console.log(obj)

mui按鈕返回父頁面重新整理

mui.plusReady(function() {       var Back = mui.back;        &n

排他佈局,導航顯示不同頁面內容。自定義屬性應用於索引。

排他佈局,點選不同導航,會顯示不同的內容。關鍵在於給導航標籤span設定自定義屬性index用於索引。這樣不同的導航索引對應下面不同內容。如:當點選產品:則顯示對應的產品模組。obj.setAttribute("index",i);  var numb=obj.getAttr

selenium連結進入子頁面抓取內容(新聞抓取案例一)

找了一個新聞網站練習爬蟲抓取,目標:逐一點選目錄標題,進入詳細新聞頁面,抓取子頁面的標題和正文內容並打印出來,返回目錄標題頁,點選下一篇文章。注:沒有新開視窗,是在原視窗實現跳轉。新開視窗進行抓取看下一篇文章。 試了很多種方法都抓取不到class=rightContent下