Number of sections in a collection view
By : Wingszero
Date : March 29 2020, 07:55 AM
hop of those help? Make sure that you have set delegate and data source to self for both collection views like code :
self.firstcollectionView.delegate = self;
self.firstcollectionView.datasource = self;
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
if (collectionView == self.cardscollectionView) {
NSLog(@"getting called. It is cardcollerctionView");
return 2;
}
if (collectionView == self.bankscollectionView) {
NSLog(@"getting called. it is bankcollectionView");
return 1;
}
else
{
return 1;
}
//use above or below both are working fine.
//******************************* OR ********************************************
if (collectionView == self.cardscollectionView) {
NSLog(@"getting called. It is cardcollerctionView");
return 2;
}
else
{
NSLog(@"it is else");
return 1;
}
}
|
Adding a certain amount of values from an Array to a Collection View
By : SoNiKBooM
Date : March 29 2020, 07:55 AM
may help you . I have an Array of UIImages that I add to a Collection View with 40 cells. I want to use an integer to choose the amount of UIImages that is taken from that Array and add a default UIImage to the remaining cells. , In cellForItem(at:): code :
if indexPath.item >= 7 {
cell.imageView?.image = defaultImage
} else {
cell.imageView?.image = imageArray[indexPath.item]
}
|
How to insert collection view sections
By : VIOR Life and Aesthe
Date : March 29 2020, 07:55 AM
To fix this issue I know how to insert items, just like this: , You can create an IndexSet with an array literal: code :
let i: IndexSet = [1, 2, 4]
let array = [4, 5, 6]
let i2 = IndexSet(array)
collectionView.insertSections([0])
|
ios - How to merge two different sections in collection view
By : cvitalent
Date : March 29 2020, 07:55 AM
help you fix your problem You can show both cell types in the same section with these changes: Add properties for the number of aCells and bCells. This is better than putting the magic numbers 3 and 1 in your code because it documents what the numbers represent. If you ever need to change them, you can change them in one spot. Change numberOfSections to return 1. Change numberOfItemsInSection to return the sum of the number of A cells and the number of B cells: return aCells + bCells. In cellForItemAt, compare indexPath.item to aCells to figure out when to switch over to B cells. code :
var aCells = 3
var bCells = 1
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return aCells + bCells
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item < aCells {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "taskCell", for: indexPath) as! CellA
cell.layer.cornerRadius = 2
cell.layer.shadowColor = UIColor(red:0.82, green:0.82, blue:0.82, alpha:1.0).cgColor
cell.layer.shadowOffset = CGSize.zero
cell.layer.shadowOpacity = 1
cell.layer.shadowRadius = 4
cell.layer.masksToBounds = false
return cell
} else {
let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "addNewCell", for: indexPath) as! CellB
return cell2
}
}
|
iPhone: Table Rows/Sections from an array - Setting amount of sections and row data from array
By : Hundo88
Date : March 29 2020, 07:55 AM
hope this fix your issue I've got the following code. The array is built up from XML, so each node has a Title (which will be the section title) and text (which will go in the cell itself)
|