2016-05-11 8 views
2

私はストーリーボードでUICollectionViewを撮影しました。私はdatasourcedelegateも設定しました。方法下記 はcollectionViewにcellForItemAtIndexPathが呼び出されていません

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

しかし- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPathが呼び出されていないと呼ばれています。

UICollectionViewのプロパティのスクリーンショットを添付しています。この問題の考え方は?私はnavigationBarを非表示にした場合image 1

enter image description here

今collectionViewが表示されます。で、これはコントローラーの最上部にあると思っています。Myheader Collection View.top = Top Layout Guide.bottom + 64方法の完了後に警告を受けています - - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

警告: 制約を同時に満たすことはできません。 おそらく、次のリストの制約の少なくとも1つは、あなたが望まないものです。 これを試してください: (1)それぞれの制約を見て、あなたが期待していないものを見つけようとしてください。 (2)不要な制約を追加したコードを見つけて修正します。 ( "< _UILayoutSupportConstraint:0x7fda80dcff20 V:[_ UILayoutGuide:0x7fda830006f0(0)]>"、 」< _UILayoutSupportConstraint:0x7fda80daca10 V:| - (0) - [_ UILayoutGuide:0x7fda830006f0](名称: '|':UIViewの:0x7fda80efb580 )>」、 ""、 "" )

制約

を破って回復を試みますデバッガでこれをキャッチするUIViewAlertForUnsatisfiableConstraintsでシンボリックブレークポイントを作成します。 UIViewのUIConstraintBasedLayoutDebuggingカテゴリのメソッドも参考になる場合があります。

+0

'numberOfItemsInSection'は呼ばれていますか?いくつの 'セクション'を指定しましたか? – luk2302

+0

私は1セクションを指定しました。 –

+0

アプリを実行した後に何が表示されますか? 1つの項目または1つではない? – Shubhank

答えて

0
[myCollectionView setContentInset:UIEdgeInsetsMake(100, 0, 0, 0)]; 

以上ラインは私の問題を解決します。

3

流れが正しく設定されていないと思います。

したがって、- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPathの方法にはなりません。そのため、ブレークポイントを設定し、それぞれのフローレイアウト方法を確認してください。 viewdidload customflowlayoutのフローレイアウト方法の

シーケンスコール、

1回目は、あなたの場合には、この方法でも

と呼ばれる、あなたは

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; 
    float ratio = self.aCollectionView.frame.size.width/3; 
    [flowLayout setItemSize:CGSizeMake(ratio, ratio)]; 
    [flowLayout setMinimumInteritemSpacing:0]; 
    [flowLayout setMinimumLineSpacing:0]; 

第二を設定している場合、//、同様に呼び出されます

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section

第3回 - この行からチェックする必要があります//正しく設定したかどうかを確認してください

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 
    float width = collectionView.frame.size.width/3;//120 
    float height = collectionView.frame.size.height/4;//120 
    return CGSizeMake(width-17,height-14); 
} 

第四に、この方法は

- (UIEdgeInsets)collectionView: 
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { 
    return UIEdgeInsetsMake(14.0, 14.0, 0.0, 14.0); 
} 

cellforitemメソッドが呼び出され、ここで最後と呼ばれます。このメソッドが呼び出されていないので、上記のメソッドに問題があります。ブレークポイントを設定してセルのサイズやエッジの昆虫などを変更しようとしてから、試してみてください。

5番目

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath

0

私はUITableViewで数年前に同様の問題があったが、解決策はストーリーボードでは、親ビューに私のコントロールからドラッグ&ドロップすることでした。ここ

だけで十分であるように思われなかった、私のObjective-Cのコードの値を設定し...

enter image description here

完全な詳細:

Setting DataSource and delegate

関連する問題