I am loading an array to UIcollectionview
(later will add other data) . I want to select collection view item randomly as:
var indexpath = Int(arc4random_uniform(UInt32(items.count)-1)
self.collectionview.selectitem(at: **indexpath**, animated:true ,scrollPosition:UICollectionViewScrollPosition)
Here it’s giving me error at bold position saying:
cannot convert value of type Int to expected argument type 'IndexPath?
I can understand this exception as indexpath
is different in swift from collection data index(array index). But I am unable to find any method that can convert item index to indexpath or anyother way.
I am newer to iOS so might be not good at searching correct keywords for such issue. It will be a great favour from you all for any other method to this requirement.
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
So to start with the indexPath. row will be 0. Then it will be 1, then 2, then 3 and so on. You do this so that you can get the correct string from the array each time.
A list of indexes that together represent the path to a specific location in a tree of nested arrays.
To create an IndexPath
in swift 3 for UICollectionView
let indexPath = IndexPath(item: 0, section: 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With