Reputation: 4402
I have taken UICollectionView
in storyboard. I have set datasource
and delegate
also.
below method is called
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 4;
}
But - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
is not called.
Attaching screenshot of properties of UICollectionView
. Any idea about this problem?
Now collectionView is visible if I hide the navigationBar. In have set top constraint Myheader Collection View.top = Top Layout Guide.bottom + 64
thought it is at top of controller. and I am receiving follwing warning after completion of method -- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
.
Warning: nable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<_UILayoutSupportConstraint:0x7fda80dcff20 V:[_UILayoutGuide:0x7fda830006f0(0)]>", "<_UILayoutSupportConstraint:0x7fda80daca10 V:|-(0)-[_UILayoutGuide:0x7fda830006f0] (Names: '|':UIView:0x7fda80efb580 )>", "", "" )
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
Upvotes: 3
Views: 5520
Reputation: 4402
[myCollectionView setContentInset:UIEdgeInsetsMake(100, 0, 0, 0)];
Above line solves my problem.
Upvotes: 0
Reputation: 7612
I think you didn't set flow out correctly.
So, it will not go to - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
method . so, set break point and check each and every flow layout method.
Sequence call of flow layout method ,
1 st in viewdidload
customflowlayout will be called like , //if you have set
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];
2nd , in your case this method also called
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
3rd - you need to check from this line , // you have set it correctly or not
- (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);
}
4th , this method called
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(14.0, 14.0, 0.0, 14.0);
}
and last here cellforitem
method is called . so, your this method not called so, problem is in above method try to set break point and change cell size and edge insect and etc and then try,
5th , if all above set correct then , below method called.
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
Upvotes: 4
Reputation: 29213
I had a similar issue a few years ago with my UITableView
, and the solution was to drag'n'drop from my control to the parent view, in the Storyboard.
Just setting the values in my Objective-C code didn't seem to be enough...
Full details here:
Setting DataSource and delegate
Upvotes: 0