Home Saving reordered uicollectionview cell not working without error
Reply: 0

Saving reordered uicollectionview cell not working without error

user2050
1#
user2050 Published in April 26, 2018, 1:46 pm

I can finally reorder the cells sucessfully in the collectionview, but I can't save despite having UserDefaults after reordering it and see the collectionview in it's reordered state after restarting the app.

func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        if collectionView == 1configcollectionview {
            let itemToMove = keystring[sourceIndexPath.row]
            keystring.remove(at: sourceIndexPath.row)
            keystring.insert(itemToMove, at: destinationIndexPath.row)
            print("Starting Index: \(sourceIndexPath.row)")
            print("Ending Index: \(destinationIndexPath.row)")
            UserDefaults.standard.set(keystring, forKey:"keystringreorder")
            //  let movekey = keystring.remove(at: sourceIndexPath.item)
            //  keystring.insert(movekey, at: destinationIndexPath.item)
        }
        if collectionView == 2configcollectionview {
            let movekey1 = keystring1.remove(at: sourceIndexPath.item)
            keystring1.insert(movekey1, at: destinationIndexPath.item)
            print("Starting Index: \(sourceIndexPath.item)")
            print("Ending Index: \(destinationIndexPath.item)")
            UserDefaults.standard.set(keystring1, forKey:"keystringreorder1")

        }
        if collectionView == 3configcollectionview {
            let movekey2 = keystring2.remove(at: sourceIndexPath.item)
            keystring2.insert(movekey2, at: destinationIndexPath.item)
            print("Starting Index: \(sourceIndexPath.item)")
            print("Ending Index: \(destinationIndexPath.item)")
            UserDefaults.standard.set(keystring2, forKey:"keystringreorder2")


        }


    }

 override func viewDidLoad() {
        super.viewDidLoad()
    let orderkeystring = UserDefaults.standard.object(forKey:"keystringreorder")
        if(orderkeystring != nil) {
            keystring = orderkeystring as! [String]
        }
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.681196 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO