Multiple UICollectionViews in ViewController | Would not call one CollectionViews Delegate methods
SO I have two UICollectionViews
in my UIViewController
in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView
delegate methods are implemented and checks for the UICollectionViews
are implemented. But it's so frustrating that one UICollectionView
is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}
and
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS
return cell
}
}
Whereas the UICollectionViews are connected like this:
and:
Please please help. Thank you so much
ios xcode uicollectionview storyboard swift4
|
show 3 more comments
SO I have two UICollectionViews
in my UIViewController
in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView
delegate methods are implemented and checks for the UICollectionViews
are implemented. But it's so frustrating that one UICollectionView
is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}
and
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS
return cell
}
}
Whereas the UICollectionViews are connected like this:
and:
Please please help. Thank you so much
ios xcode uicollectionview storyboard swift4
Remove the delegate connection for the working collection view and check if data source methods are executed for thevariantsCollectionView
at all.
– Evgeniy
Nov 23 '18 at 13:36
If they do, thenif collectionView == self.variantsCollectionView {
not working. In that case, check if IBOutlet forvariantsCollectionView
is connected properly.
– Evgeniy
Nov 23 '18 at 13:38
@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39
Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42
1
Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51
|
show 3 more comments
SO I have two UICollectionViews
in my UIViewController
in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView
delegate methods are implemented and checks for the UICollectionViews
are implemented. But it's so frustrating that one UICollectionView
is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}
and
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS
return cell
}
}
Whereas the UICollectionViews are connected like this:
and:
Please please help. Thank you so much
ios xcode uicollectionview storyboard swift4
SO I have two UICollectionViews
in my UIViewController
in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView
delegate methods are implemented and checks for the UICollectionViews
are implemented. But it's so frustrating that one UICollectionView
is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}
and
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS
return cell
}
}
Whereas the UICollectionViews are connected like this:
and:
Please please help. Thank you so much
ios xcode uicollectionview storyboard swift4
ios xcode uicollectionview storyboard swift4
asked Nov 23 '18 at 13:34
Mohsin Khubaib Ahmed
7601322
7601322
Remove the delegate connection for the working collection view and check if data source methods are executed for thevariantsCollectionView
at all.
– Evgeniy
Nov 23 '18 at 13:36
If they do, thenif collectionView == self.variantsCollectionView {
not working. In that case, check if IBOutlet forvariantsCollectionView
is connected properly.
– Evgeniy
Nov 23 '18 at 13:38
@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39
Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42
1
Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51
|
show 3 more comments
Remove the delegate connection for the working collection view and check if data source methods are executed for thevariantsCollectionView
at all.
– Evgeniy
Nov 23 '18 at 13:36
If they do, thenif collectionView == self.variantsCollectionView {
not working. In that case, check if IBOutlet forvariantsCollectionView
is connected properly.
– Evgeniy
Nov 23 '18 at 13:38
@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39
Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42
1
Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51
Remove the delegate connection for the working collection view and check if data source methods are executed for the
variantsCollectionView
at all.– Evgeniy
Nov 23 '18 at 13:36
Remove the delegate connection for the working collection view and check if data source methods are executed for the
variantsCollectionView
at all.– Evgeniy
Nov 23 '18 at 13:36
If they do, then
if collectionView == self.variantsCollectionView {
not working. In that case, check if IBOutlet for variantsCollectionView
is connected properly.– Evgeniy
Nov 23 '18 at 13:38
If they do, then
if collectionView == self.variantsCollectionView {
not working. In that case, check if IBOutlet for variantsCollectionView
is connected properly.– Evgeniy
Nov 23 '18 at 13:38
@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39
@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39
Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42
Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42
1
1
Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51
Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51
|
show 3 more comments
1 Answer
1
active
oldest
votes
Via comments the TS found solution by following these steps:
- Ensure both collection views have non-nil data sources (and delegates).
- Check that data source methods are executed for both collection view.
- Check that both collection views' cells have valid size.
Finally the problem was found after checking the heights of each collection view inside stack view.
basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447698%2fmultiple-uicollectionviews-in-viewcontroller-would-not-call-one-collectionview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Via comments the TS found solution by following these steps:
- Ensure both collection views have non-nil data sources (and delegates).
- Check that data source methods are executed for both collection view.
- Check that both collection views' cells have valid size.
Finally the problem was found after checking the heights of each collection view inside stack view.
basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.
add a comment |
Via comments the TS found solution by following these steps:
- Ensure both collection views have non-nil data sources (and delegates).
- Check that data source methods are executed for both collection view.
- Check that both collection views' cells have valid size.
Finally the problem was found after checking the heights of each collection view inside stack view.
basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.
add a comment |
Via comments the TS found solution by following these steps:
- Ensure both collection views have non-nil data sources (and delegates).
- Check that data source methods are executed for both collection view.
- Check that both collection views' cells have valid size.
Finally the problem was found after checking the heights of each collection view inside stack view.
basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.
Via comments the TS found solution by following these steps:
- Ensure both collection views have non-nil data sources (and delegates).
- Check that data source methods are executed for both collection view.
- Check that both collection views' cells have valid size.
Finally the problem was found after checking the heights of each collection view inside stack view.
basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.
answered Nov 23 '18 at 14:09
Evgeniy
477413
477413
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447698%2fmultiple-uicollectionviews-in-viewcontroller-would-not-call-one-collectionview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Remove the delegate connection for the working collection view and check if data source methods are executed for the
variantsCollectionView
at all.– Evgeniy
Nov 23 '18 at 13:36
If they do, then
if collectionView == self.variantsCollectionView {
not working. In that case, check if IBOutlet forvariantsCollectionView
is connected properly.– Evgeniy
Nov 23 '18 at 13:38
@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39
Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42
1
Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51