2015-11-12 92 views
1

在我的項目中,我有一個UITableView不同類型的單元格。 其中一個單元格包含水平滾動UICollectionViewUITableView中的水平UICollectionView不滾動

當我運行我的項目時,UICollectionView正確填充,但我不能水平滾動,單擊並拖動此UICollectionView只允許我垂直滾動tableview。

所需的行爲是使用UICollectionView單元格內的點擊將允許用戶水平滾動,單擊任何其他單元格允許垂直滾動。

我假設我需要覆蓋/傳遞或禁用此單元格中的一些OnClick事件,但我找不到正確的解決方案。

指着我好的方向發展的任何幫助,將不勝感激:)

用於創建關於TableViewCell的代碼看起來是這樣的。

@property(nonatomic) HorizontalCollectionViewDelegate *horizontalCollectionViewDelegate; 
- (UITableViewCell *) createHorizontalScrollCell:(NSIndexPath *)indexPath tableView:(UITableView *)tableView{ 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellIdentifier]; 
     MyHorizontalScrollingTableCell *myHorizontalScrollingTableCell = (MyHorizontalScrollingTableCell *)cell; 

     UICollectionView *horizontalCollectionView = myHorizontalScrollingTableCell.myHorizontalCollectionView; 

     //Link collectionView to its delegate 
     self.horizontalCollectionViewDelegate = [[HorizontalCollectionViewDelegate alloc] init]; 
     horizontalCollectionView.delegate = _horizontalCollectionViewDelegate; 
     horizontalCollectionView.dataSource = _horizontalCollectionViewDelegate; 
     _horizontalCollectionViewDelegate.data = myData; 

     //Define the cells in HorizontalCollectionView 
     UINib *cellNib = [UINib nibWithNibName:@"CollectionViewCell" bundle:nil]; 
     [horizontalCollectionView registerNib:cellNib forCellWithReuseIdentifier:@"horizCell"]; 

     //Define flow of AttachmentsCollectionView 
     UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
     [flowLayout setItemSize:CGSizeMake(90, 90)]; 
     [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 
     [horizontalCollectionView setCollectionViewLayout:flowLayout]; 

     return cell; 
    } 

編輯:我使用的是相同的Horizo​​ntalCollectionViewDelegate其他地方在我的項目(不只是在實現代碼如下),並在那裏是工作,所以我想這個問題是不存在的。

編輯2:問題解決了,結果是沒有問題(見下面的答案),我會在兩天內接受我的答案。

+1

水平滾動tableview與細胞刷卡衝突刪除!我建議你使用collectionview來達到橫向滾動的目的,但不能在表格視圖中使用!如果你想擁有它們,使用scrollview和uiview來設計你的自定義視圖! –

+0

應該不可以覆蓋此滑動刪除行爲?在這個博客似乎工作,但我不知道如何:p http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/ – RWIL

回答

1

解決...

原來我只是需要更多的內容添加到UICollectionView

使用2或3個元素時,單元格未填充完整視圖。由於沒有顯示滑動動畫,我假設某處出現了錯誤。

但是,只是添加更多的內容解決了這個問題。