[英]Horizontal UICollectionView in UITableView not scrolling
在我的項目中,我有一個帶有不同類型單元格的UITableView
。 其中一個單元格包含一個水平滾動的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;
}
編輯:我在我的項目中的其他地方使用相同的 HorizontalCollectionViewDelegate(只是不在 tableview 中)並且在那里它正在工作,所以我認為問題不存在。
編輯 2 :問題解決了,結果沒有問題(見下面的答案),我會在兩天內接受我的答案。
解決了...
結果我只需UICollectionView
添加更多內容。
對於 2 或 3 個元素,單元格沒有填滿整個視圖。 因為沒有顯示滑動動畫,所以我認為某處有錯誤。
但是,只需添加更多內容即可解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.