Preload UICollectionView cells












-1















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!!!










share|improve this question

























  • 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
















-1















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!!!










share|improve this question

























  • 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














-1












-1








-1








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!!!










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















0














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)
}





share|improve this answer
























  • 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













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
});


}
});














draft saved

draft discarded


















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









0














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)
}





share|improve this answer
























  • 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


















0














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)
}





share|improve this answer
























  • 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
















0












0








0







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)
}





share|improve this answer













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)
}






share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage