ViewController中有多个UICollectionView不会调用一个CollectionViews委托方法

时间:2018-11-23 13:34:15

标签: ios xcode uicollectionview storyboard swift4

所以我在Storyboard的UICollectionViews中有两个UIViewController,并且两者都与委托和数据源链接到了我的ViewController。所有关联的UICollectionView委托方法都已实现,并且UICollectionViews的检查也已实现。但是令人沮丧的是,一个UICollectionView被照顾了,而另一个func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if collectionView == self.variantsCollectionView { // let count = (item?.variant_groups?.count)! return 1 } else { return 2//(item?.extra_groups?.count)! } } 被完全忽略了。我在所有可用方面都抓狂了,但是这使我更趋边缘,请帮忙。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

        if collectionView == self.variantsCollectionView {
            //IT DOESNT EVEN COME HERE AT ALL
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
            return cell

        } else {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
            //HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS

            return cell
        }

    }

P.when('A').register("ImageBlockATF", function(A){

    var data = {

                'colorImages': { 'initial': [{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX355_.jpg":[219,355],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX450_.jpg":[278,450],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX425_.jpg":[263,425],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX466_.jpg":[288,466],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX522_.jpg":[323,522],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX569_.jpg":[352,569],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX679_.jpg":[420,679]},"variant":"MAIN","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX355_.jpg":[215,355],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX450_.jpg":[272,450],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX425_.jpg":[257,425],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX466_.jpg":[282,466],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX522_.jpg":[315,522],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX569_.jpg":[344,569],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX679_.jpg":[410,679]},"variant":"PT01","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX355_.jpg":[217,355],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX450_.jpg":[275,450],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX425_.jpg":[260,425],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX466_.jpg":[285,466],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX522_.jpg":[319,522],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX569_.jpg":[348,569],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX679_.jpg":[415,679]},"variant":"PT02","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX679_.jpg":[478,679]},"variant":"PT03","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX355_.jpg":[266,355],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX450_.jpg":[338,450],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX425_.jpg":[319,425],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX466_.jpg":[350,466],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX522_.jpg":[392,522],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX569_.jpg":[427,569],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX679_.jpg":[509,679]},"variant":"PT04","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX679_.jpg":[679,679]},"variant":"PT05","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX679_.jpg":[679,679]},"variant":"PT06","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX355_.jpg":[251,355],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX450_.jpg":[318,450],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX425_.jpg":[301,425],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX466_.jpg":[330,466],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX522_.jpg":[369,522],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX569_.jpg":[402,569],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX679_.jpg":[480,679]},"variant":"PT07","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX679_.jpg":[477,679]},"variant":"PT08","lowRes":null}]},

                'colorToAsin': {'initial': {}},

                'holderRatio': 1.0,

                'holderMaxHeight': 700,

                'heroImage': {'initial': []},

                'heroVideo': {'initial': []},

                'spin360ColorData': {'initial': {}},

                'spin360ColorEnabled': {'initial': 0},

                'spin360ConfigEnabled': false,

                'spin360LazyLoadEnabled': false,

                'playVideoInImmersiveView':'false',

                'tabbedImmersiveViewTreatment':'T2',

                'totalVideoCount':'0',

                'videoIngressATFSlateThumbURL':'',

                'mediaTypeCount':'0',

                'atfEnhancedHoverOverlay' : true,

                'winningAsin': 'B07HGMDY4T',

                'weblabs' : {},

                'aibExp3Layout' : 1,

                'aibRuleName' : 'R17',

                'acEnabled' : false

                };

    A.trigger('P.AboveTheFold'); // trigger ATF event.

    return data;

});

UICollectionViews的连接方式如下: enter image description here

和: enter image description here

请帮助。非常感谢

1 个答案:

答案 0 :(得分:1)

通过以下步骤评论TS找到的解决方案:

  1. 确保两个集合视图都具有非零数据源(和委托)。
  2. 检查是否对两个集合视图都执行了数据源方法。
  3. 检查两个集合视图的单元格的大小是否有效。

最后,检查堆栈视图内每个集合视图的高度后发现了问题。

  

基本上CollectionView具有特定的高度,而   VariantCollectionView没有,并且都在stackView中。第一次的时候   鉴于它占据了整个尺寸,而其他   种实际上消失了。因此是问题。