Preload UICollectionView cells
I'm loading a collection view inside a tableview. There are 400 cells in collection view (Horizontal). I want to select a particular cell to highlight it. Sample is like, totalCells = 400 cellToBeHighlighted = 350
Here's my code in viewDidLayoutSubView of my ViewController
let cell = tableView.cellForRow(at: IndexPath(row: 5, section: 0)) as! MyCollectionCell // Tableview cell which loads collection view inside
let indexPath = IndexPath(row:350, section: 0)
cell.collectionView.scrollToItem(at: indexPath, at: UICollectionView.ScrollPosition.left, animated: true)
Since 350th cell will not be loaded initially, scroll is not working. Any help will be appreciated.
Thanks in advance!!!
ios uicollectionview
add a comment |
I'm loading a collection view inside a tableview. There are 400 cells in collection view (Horizontal). I want to select a particular cell to highlight it. Sample is like, totalCells = 400 cellToBeHighlighted = 350
Here's my code in viewDidLayoutSubView of my ViewController
let cell = tableView.cellForRow(at: IndexPath(row: 5, section: 0)) as! MyCollectionCell // Tableview cell which loads collection view inside
let indexPath = IndexPath(row:350, section: 0)
cell.collectionView.scrollToItem(at: indexPath, at: UICollectionView.ScrollPosition.left, animated: true)
Since 350th cell will not be loaded initially, scroll is not working. Any help will be appreciated.
Thanks in advance!!!
ios uicollectionview
For cells you want to be highlighted set .isSelected = true
– canister_exister
16 hours ago
Collection view cell is nil. Here's my code let collectionViewCell = cell.collectionView.cellForItem(at: indexPath) collectionViewCell?.isSelected = true
– Sivagami
10 hours ago
add a comment |
I'm loading a collection view inside a tableview. There are 400 cells in collection view (Horizontal). I want to select a particular cell to highlight it. Sample is like, totalCells = 400 cellToBeHighlighted = 350
Here's my code in viewDidLayoutSubView of my ViewController
let cell = tableView.cellForRow(at: IndexPath(row: 5, section: 0)) as! MyCollectionCell // Tableview cell which loads collection view inside
let indexPath = IndexPath(row:350, section: 0)
cell.collectionView.scrollToItem(at: indexPath, at: UICollectionView.ScrollPosition.left, animated: true)
Since 350th cell will not be loaded initially, scroll is not working. Any help will be appreciated.
Thanks in advance!!!
ios uicollectionview
I'm loading a collection view inside a tableview. There are 400 cells in collection view (Horizontal). I want to select a particular cell to highlight it. Sample is like, totalCells = 400 cellToBeHighlighted = 350
Here's my code in viewDidLayoutSubView of my ViewController
let cell = tableView.cellForRow(at: IndexPath(row: 5, section: 0)) as! MyCollectionCell // Tableview cell which loads collection view inside
let indexPath = IndexPath(row:350, section: 0)
cell.collectionView.scrollToItem(at: indexPath, at: UICollectionView.ScrollPosition.left, animated: true)
Since 350th cell will not be loaded initially, scroll is not working. Any help will be appreciated.
Thanks in advance!!!
ios uicollectionview
ios uicollectionview
edited yesterday
Sivagami
asked yesterday
SivagamiSivagami
81111
81111
For cells you want to be highlighted set .isSelected = true
– canister_exister
16 hours ago
Collection view cell is nil. Here's my code let collectionViewCell = cell.collectionView.cellForItem(at: indexPath) collectionViewCell?.isSelected = true
– Sivagami
10 hours ago
add a comment |
For cells you want to be highlighted set .isSelected = true
– canister_exister
16 hours ago
Collection view cell is nil. Here's my code let collectionViewCell = cell.collectionView.cellForItem(at: indexPath) collectionViewCell?.isSelected = true
– Sivagami
10 hours ago
For cells you want to be highlighted set .isSelected = true
– canister_exister
16 hours ago
For cells you want to be highlighted set .isSelected = true
– canister_exister
16 hours ago
Collection view cell is nil. Here's my code let collectionViewCell = cell.collectionView.cellForItem(at: indexPath) collectionViewCell?.isSelected = true
– Sivagami
10 hours ago
Collection view cell is nil. Here's my code let collectionViewCell = cell.collectionView.cellForItem(at: indexPath) collectionViewCell?.isSelected = true
– Sivagami
10 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Please try invoking the scrollToItem function at a place where the collectionview is guaranteed to have laid out it's subviews. I tried the following and was able to scroll to the 350th cell
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.scrollToItem(at: IndexPath(item: 349, section: 0) , at: .centeredHorizontally, animated: true)
}
Still same issue persists for me
– Sivagami
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
Please look at updated question
– Sivagami
yesterday
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%2f54251087%2fpreload-uicollectionview-cells%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
Please try invoking the scrollToItem function at a place where the collectionview is guaranteed to have laid out it's subviews. I tried the following and was able to scroll to the 350th cell
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.scrollToItem(at: IndexPath(item: 349, section: 0) , at: .centeredHorizontally, animated: true)
}
Still same issue persists for me
– Sivagami
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
Please look at updated question
– Sivagami
yesterday
add a comment |
Please try invoking the scrollToItem function at a place where the collectionview is guaranteed to have laid out it's subviews. I tried the following and was able to scroll to the 350th cell
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.scrollToItem(at: IndexPath(item: 349, section: 0) , at: .centeredHorizontally, animated: true)
}
Still same issue persists for me
– Sivagami
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
Please look at updated question
– Sivagami
yesterday
add a comment |
Please try invoking the scrollToItem function at a place where the collectionview is guaranteed to have laid out it's subviews. I tried the following and was able to scroll to the 350th cell
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.scrollToItem(at: IndexPath(item: 349, section: 0) , at: .centeredHorizontally, animated: true)
}
Please try invoking the scrollToItem function at a place where the collectionview is guaranteed to have laid out it's subviews. I tried the following and was able to scroll to the 350th cell
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.scrollToItem(at: IndexPath(item: 349, section: 0) , at: .centeredHorizontally, animated: true)
}
answered yesterday
humblePilgrimhumblePilgrim
93931741
93931741
Still same issue persists for me
– Sivagami
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
Please look at updated question
– Sivagami
yesterday
add a comment |
Still same issue persists for me
– Sivagami
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
Please look at updated question
– Sivagami
yesterday
Still same issue persists for me
– Sivagami
yesterday
Still same issue persists for me
– Sivagami
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
can you please post the relevant methods that are used for populating the collection view ? What actually happens ? Do you get an error ? If so please mention that.
– humblePilgrim
yesterday
Please look at updated question
– Sivagami
yesterday
Please look at updated question
– Sivagami
yesterday
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%2f54251087%2fpreload-uicollectionview-cells%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 cells you want to be highlighted set .isSelected = true
– canister_exister
16 hours ago
Collection view cell is nil. Here's my code let collectionViewCell = cell.collectionView.cellForItem(at: indexPath) collectionViewCell?.isSelected = true
– Sivagami
10 hours ago