2

我在我的UITableviewCell中使用了UICollectionView,一切正常,仍在加載集合視圖並顯示其單元格,但加載集合視圖後,我無法獲取「didSelectItemAtIndexPath 「點擊集合視圖單元格時的集合視圖的委託方法。當在UITableviewCell中使用UICollection視圖時不調用UICollectionView委託方法「didSelectItemAtIndexPath」

有靜態細胞和我把收集鑑於該小區

而且其上定義

這裏的委託和數據源我的表視圖是我叫,但委職能不叫代碼,數據源方法

collectioview和委託和數據源的
#pragma mark - collectionView data source 


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return 10; 
} 

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collCell" forIndexPath:indexPath]; 
    UIImageView *imgDocCell = (UIImageView *)[cell viewWithTag:100]; 
    imgDocCell.image = self.imgFileToChart; 
    cell.layer.borderWidth=1.0f; 
    cell.layer.borderColor=commonThemeColor.CGColor; 
    return cell; 
} 


#pragma mark - collectionView delegate 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"%@",indexPath); 
} 
+0

'collectionView data source' code added where? –

+1

我認爲它採取tableview委託方法。將斷點放在tableview委託方法中,並檢查它 –

+0

@ Mr.Bista在我的tableview控制器 –

回答

-2

刪除出口過,見OUTPUT HERE

你應該寫你的這樣的代碼

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *MyIdentifier = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    // Here tableviewcell inside one collection view create with tag 10 
    UICollectionView *coll =(UICollectionView*)[cell viewWithTag:10]; 
    coll.delegate = self; 
    coll.dataSource = self; 

    return cell; 
} 
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return 3; 
} 

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell2" forIndexPath:indexPath]; 
    // in collectionview storyboard one UIImageview with tag 20 
    UIImageView *imgDocCell = (UIImageView *)[cell1 viewWithTag:20]; 
    imgDocCell.image =[UIImage imageNamed:@"add.jpeg"]; 

    return cell1; 
} 

#pragma mark - collectionView delegate 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"%@",indexPath); 
} 
+0

誰給這篇文章downvote?請檢查代碼,如果不正確,然後downvote它 –

+0

當你寫'UICollectionView * coll =(UICollectionView *)[cell viewWithTag:10];'時,你不能告訴用戶複製粘貼你的代碼。那是什麼? –

+0

@ LucaD'Alberti See bro它的共同點,程序員必須明白,我必須在這裏給自己的標籤 –

相關問題