logo
down
shadow

Why is array in collection view getting multiplied by amount of sections?


Why is array in collection view getting multiplied by amount of sections?

By : user3099629
Date : January 11 2021, 03:34 PM
Does that help Since you have three cells per section, and assuming you have only one section, collectionView(_:cellForItemAt:) gets called three times. Each time you are printing all the elements of the numbers array. To only print the element corresponding to the current index, replace the for loop by:
code :
print(numbers[indexPath.row])


Share : facebook icon twitter icon
Number of sections in a collection view

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

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

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

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

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)
Related Posts Related Posts :
  • How to connect an iPhone app (rest) to XAMPP using a local WIFI connection?
  • Swift 4 delegate is not working with tabbar controller
  • How do i compile all contact's phone numbers into one cell - using CNContact
  • How do I change the color of two UIButtons when I press them?
  • UIViewPropertyAnimator doesn’t work as expected
  • GoogleMaps camera target in top left corner of map iOS since pod update
  • Allowing SwiftUI to import all Contacts and delete specific ones
  • How can I obtain POST request body from WKWebView in Swift?
  • How is enumerated() constant time O(1)?
  • How to get XML data and bind in tableview in iOS Swift?
  • Interface Builder Constraints Problems
  • Xcode 11 beta can't upload app to TestFlight
  • iOS odd Thread 1: Fatal error: Index out of range on iPad
  • Cannot convert json object to struct
  • How can I prevent the stopwatch from resetting after pause
  • Cannot convert value of type '() -> _' to specified type '[UIViewController]'
  • How to make a reference to a uid stored in Firestore?
  • How do you initialize/use UITableViewCells with CellStyle = .value1 programmatically?
  • How to know if Apple has received our appeal/how long does it take Apple to respond?
  • Select new item added to SwiftUI List
  • What is the correct length: argument to provide to NSRange for NSRegularExpression using a (Swift) String?
  • I am trying to delete data from database, but sometime data is deleted and sometime data is not deleted
  • How to get slider value with subview rotation angle
  • Can't pass custom UINavigationBar / UIToolbar to UINavigationController because they don't conform to AnyClass
  • Remove app before simulator or device is lunched from Xcode
  • Auto Layout constraints for container view inside UITableView header broken for different devices
  • iPhone restarts after API call
  • What is the shortcut / How do I create function after writing it's usage in Xcode
  • Convert apple time stamp to Unix time
  • No podspec found for `React-fishhook`
  • How to test touch dialog and perform real in-app purchase?
  • Compiling Metal shaders from source on iOS 13 Simulator gives PCH error
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org