ios


Scroll conflict for multiple CollectionView in a ViewController


I have two UICollectionView collectionViewA and collectionViewB in my ViewController, collectionViewB is presented as a subView when a button is tapped, the issue i have now is that when i scroll on collectionViewB, collectionViewA scrolls too, is there a way to only scroll for the active collectionView without affecting the second.?
extension TrendListVC: UICollectionViewDelegate,
UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.collectionViewForSubView{
return count
}
return 60
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.collectionViewForSubView{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! ModalViewCell
//let setting = settings[indexPath.item]
//cell.setting = setting
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath) as! CollectionCell
cell.itemNameLabel.text = "Name".uppercased()
return cell
}
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
var reusableView : CollectionHeader? = nil
if collectionView == self.collectionView{
if (kind == UICollectionElementKindSectionHeader) {
let head = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerCell", for: indexPath) as! CollectionHeader
head.trendListVc = self
head.headerHeightConstraint = headerHeightConstraint
reusableView = head
}
}
return reusableView!
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if collectionView == self.collectionViewForSubView{
if count % 2 != 0 && indexPath.item == count - 1{
let paddingSpace = sectionInsets.left * (itemsPerRowForSubView + 1)
let availableWidth = collectionViewForSubView.frame.width - paddingSpace
return CGSize(width: availableWidth + 23, height: cellHeight)
}else{
let paddingSpace = sectionInsets.left * (itemsPerRowForSubView + 1)
let availableWidth = collectionViewForSubView.frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRowForSubView
return CGSize(width: widthPerItem, height: cellHeight)
}
}else{
let paddingSpace = sectionInsets.left * (2 + 1)
let availableWidth = view.frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRow
return CGSize(width: widthPerItem + 4, height: widthPerItem)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
if collectionView == self.collectionView{
return CGSize(width: view.frame.width, height: 50)
}else{
return CGSize(width: 0, height: 0)
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView == self.collectionView{
showControllerForSetting(setting: "Name")
}else if collectionView == self.collectionViewForSubView{
print("Some thing")
}
}
}
This is most likely due to using your ViewController as delegate and datasource for both of your collection views. You need to create separate delegate classes for each collection view.

Related Links

iOS - What Objective-C Methods Do I Need To Make IBInspectable Work?
Star printing not formatting correctly
Refresh section header after loading user's image
how to change autolayout constraints
How to just add underline below the second line of text in a Bar Button Item?
Cropping UIImage by custom shape
Swift 3.0 CIEdgeWork filter not working
How to support both landscape and portrait in ONLY ONE UIView
how to programmatically set action for barButtonItem in swift 3?
How to fetch the phone number for the imessage extension created application
WKWebView with Basic Authentication in Swift complete example
Swift inheritance and Segmentation fault 11
Get Bluetooth Data on iWatch
unity5.3.5f1 export to Xcode, build failure: Undefined symbols for arm64. “_DeviceInfoGetDeviceIMSI”
UIview custom class including a tapgesture is it possible?
iPhone 7 and 7 Plus compatibility and showing compatibility in the app store

Categories

HOME
ffmpeg
sqlite
clojure
pyqt5
auth0
load
configuration
applet
stripe-payments
gluon
spi
sony
google-analytics-api
jfreechart
microsoft-dynamics
player-swift
librsvg
python-2.5
round-robin
gitlab-ci-runner
jscodeshift
multiprocessing
polynomials
eonasdan-datetimepicker
background-subtraction
iteration
scalability
text-parsing
trial
breakpoint-sass
django-users
dlopen
hamcrest
outlook-vba
delete-row
presto
microsoft-translator
bezier
partition
flags
visualsvn-server
compass-lucene
word-embedding
freerdp
karnaugh-map
distributed-lock
program-slicing
hostapd
sql-insert
clientscript
ssms-2012
uifont
notimplementedexception
ctl
jasmine2.0
canopen
derbyjs
maven-versions-plugin
jahia
jvm-arguments
angular-directive
blocking
statistics-bootstrap
codeigniter-upload
sql-server-2016-express
vsvim
android-popupwindow
xirr
interpreted-language
cbc-mode
structured-programming
react-rails
genexus-gam
office-2010
gdk
express-jwt
jquery-backstretch
hebrew
xml.modify
acts-as-taggable-on
freemind
re2c
polarssl
rte
visual-assist
chromeless
vote
lungojs
libavg
hpple
expressionvisitor
ruby-1.9.2
facebook-authentication
blackberry-os-v5
formsauthentication
polyglot
clipboard-pictures
help-authoring
development-machine
palm-pre
graceful-degradation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App