Multiple collection view in table view scrolling at the same time
I have collection view as rows of a tableview. The collection view only supports horizontal scrolling. When I scroll to the end of the collection view in the first row, and then scroll to the bottom of the tableview. The last collection view is also at the end position when I haven't even touched that yet.
I know that the issue is because of dequeueReusableCell
of the tableview. I have tried using the prepareForReuse()
in UITableViewCell
.
I expect that whenever any other row of the table view should remain unaffected by the interaction done on rest of the table view rows.
ios swift uitableview uicollectionview
add a comment |
I have collection view as rows of a tableview. The collection view only supports horizontal scrolling. When I scroll to the end of the collection view in the first row, and then scroll to the bottom of the tableview. The last collection view is also at the end position when I haven't even touched that yet.
I know that the issue is because of dequeueReusableCell
of the tableview. I have tried using the prepareForReuse()
in UITableViewCell
.
I expect that whenever any other row of the table view should remain unaffected by the interaction done on rest of the table view rows.
ios swift uitableview uicollectionview
for doing this you need to store last visible indexpath of collection view in model and when ever willDisplayCell called you need to animate collection view to that position
– chirag shah
Jan 1 at 13:42
I can identify the last visible cell usingcollectionView.visibleCells.first
. But how to get the indexpath for this
– iVvaibhav
Jan 1 at 13:51
1
You need to show your code, otherwise we’re just guessing.
– Magnas
Jan 1 at 13:57
add a comment |
I have collection view as rows of a tableview. The collection view only supports horizontal scrolling. When I scroll to the end of the collection view in the first row, and then scroll to the bottom of the tableview. The last collection view is also at the end position when I haven't even touched that yet.
I know that the issue is because of dequeueReusableCell
of the tableview. I have tried using the prepareForReuse()
in UITableViewCell
.
I expect that whenever any other row of the table view should remain unaffected by the interaction done on rest of the table view rows.
ios swift uitableview uicollectionview
I have collection view as rows of a tableview. The collection view only supports horizontal scrolling. When I scroll to the end of the collection view in the first row, and then scroll to the bottom of the tableview. The last collection view is also at the end position when I haven't even touched that yet.
I know that the issue is because of dequeueReusableCell
of the tableview. I have tried using the prepareForReuse()
in UITableViewCell
.
I expect that whenever any other row of the table view should remain unaffected by the interaction done on rest of the table view rows.
ios swift uitableview uicollectionview
ios swift uitableview uicollectionview
asked Jan 1 at 13:40
iVvaibhaviVvaibhav
4019
4019
for doing this you need to store last visible indexpath of collection view in model and when ever willDisplayCell called you need to animate collection view to that position
– chirag shah
Jan 1 at 13:42
I can identify the last visible cell usingcollectionView.visibleCells.first
. But how to get the indexpath for this
– iVvaibhav
Jan 1 at 13:51
1
You need to show your code, otherwise we’re just guessing.
– Magnas
Jan 1 at 13:57
add a comment |
for doing this you need to store last visible indexpath of collection view in model and when ever willDisplayCell called you need to animate collection view to that position
– chirag shah
Jan 1 at 13:42
I can identify the last visible cell usingcollectionView.visibleCells.first
. But how to get the indexpath for this
– iVvaibhav
Jan 1 at 13:51
1
You need to show your code, otherwise we’re just guessing.
– Magnas
Jan 1 at 13:57
for doing this you need to store last visible indexpath of collection view in model and when ever willDisplayCell called you need to animate collection view to that position
– chirag shah
Jan 1 at 13:42
for doing this you need to store last visible indexpath of collection view in model and when ever willDisplayCell called you need to animate collection view to that position
– chirag shah
Jan 1 at 13:42
I can identify the last visible cell using
collectionView.visibleCells.first
. But how to get the indexpath for this– iVvaibhav
Jan 1 at 13:51
I can identify the last visible cell using
collectionView.visibleCells.first
. But how to get the indexpath for this– iVvaibhav
Jan 1 at 13:51
1
1
You need to show your code, otherwise we’re just guessing.
– Magnas
Jan 1 at 13:57
You need to show your code, otherwise we’re just guessing.
– Magnas
Jan 1 at 13:57
add a comment |
1 Answer
1
active
oldest
votes
You could store (and restore) the collection views' content offsets by using the table view's delegate methods:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
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%2f53995919%2fmultiple-collection-view-in-table-view-scrolling-at-the-same-time%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
You could store (and restore) the collection views' content offsets by using the table view's delegate methods:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
add a comment |
You could store (and restore) the collection views' content offsets by using the table view's delegate methods:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
add a comment |
You could store (and restore) the collection views' content offsets by using the table view's delegate methods:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
You could store (and restore) the collection views' content offsets by using the table view's delegate methods:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
answered Jan 1 at 14:18
André SlottaAndré Slotta
9,85711325
9,85711325
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
add a comment |
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
Perfect. Thank you so much.
– iVvaibhav
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
You're welcome!
– André Slotta
Jan 1 at 14:33
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.
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%2f53995919%2fmultiple-collection-view-in-table-view-scrolling-at-the-same-time%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
for doing this you need to store last visible indexpath of collection view in model and when ever willDisplayCell called you need to animate collection view to that position
– chirag shah
Jan 1 at 13:42
I can identify the last visible cell using
collectionView.visibleCells.first
. But how to get the indexpath for this– iVvaibhav
Jan 1 at 13:51
1
You need to show your code, otherwise we’re just guessing.
– Magnas
Jan 1 at 13:57