stuffrabbit / SwiftSpreadsheet

Spreadsheet CollectionViewLayout in Swift. Fully customizable. 🔶
MIT License
641 stars 39 forks source link

How to change label text of DecorationViews?? #9

Closed codingdoze closed 3 years ago

codingdoze commented 4 years ago

thanks for the awesome library!! I can just create another nib file but I was wondering how to change label text on the fly.. Things I've tried..

//First I registered decorationview as SupplementaryView

self.collectionView.register(topRightDecorationViewNib, forSupplementaryViewOfKind: SpreadsheetLayout.ViewKindType.decorationTopRight.rawValue, withReuseIdentifier: self.defaultSupplementaryViewIdentifier)

//Lastly I tried to access it under ViewKind

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        guard let viewKind = SpreadsheetLayout.ViewKindType(rawValue: kind) else { fatalError("View Kind not available for string: \(kind)") }

        let supplementaryView = collectionView.dequeueReusableSupplementaryView(ofKind: viewKind.rawValue, withReuseIdentifier: self.defaultSupplementaryViewIdentifier, for: indexPath) as! SpreadsheetCollectionReusableView

        supplementaryView.headerDelegate = self
        switch viewKind {
        case .leftRowHeadline:
             if indexPath.section >= 0 && indexPath.section < self.LastPaymentReceiptArray.count {
                supplementaryView.infoLabel.text = self.LastPaymentReceiptArray[indexPath.section].partynm
            }
        case .rightRowHeadline:
            supplementaryView.adjustmentButton.tag = indexPath.section
        case .topColumnHeader:
            supplementaryView.infoLabel.text = self.topHeaderLabels[indexPath.item]

        case .decorationTopRight:
//Here I try to mutate the label 
            supplementaryView.infoLabel.text = "View Adjustment"

        default:
            break
        }

        return supplementaryView
    }
stuffrabbit commented 4 years ago

Hi, thanks for using this Lib, I'm glad you like it. Unfortunately, dynamically updating contents inside of decoration views is not possible (at least it used to be around iOS 12, but I guess that there did not change much ever since). There are, however, certain workarounds to make it work. You might want to take a look in this closed issue: https://github.com/stuffrabbit/SwiftSpreadsheet/issues/6. Hope this helps. Let me know if you find a solution.

Wojtek