Adding a UITableView to a UICollectionViewCell












0















I'm trying to embed a UITableView into a UICollectionViewCell. I'm managing to get everything to load. However, when it does load it up it seems to randomly use the last loaded value for the UITableView List Items. My DebugPrint Output seems to load all of the CollectionViewCells before even referencing the TableView. Once the CollectionViewCells are set, then it populates the TableView with whatever value it is left with. How can I resolve this so that I'm using the correct values? I suspect it is something to how I'm using IndexPath however I'm fairly new to Swift.



Example WireFrame



Populating UICollectionView



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: releaseIdentifier, for: indexPath) as! ReleaseCollectionViewCell

let vid: VideoItem
vid = Video[indexPath.item]

let rating = vid.Rating
let denominator = 2.0
let roundedRating = round(rating*denominator )/denominator

if vid.SiteVideoID != 0 {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/sitePictures/(GetFilePath(ID: String(vid.SiteVideoID)))/(String(vid.SiteVideoID)).jpg")
} else {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/pictures/(GetFilePath(ID: String(vid.VideoID)))/(String(vid.VideoID))_001.png")
}

cell.ReleaseDate.text = vid.ReleaseDate
cell.ReleaseTitle.text = vid.Title

cell.SiteLogo.setImageFromURl(stringImageUrl: "(file.BaseURL)/siteLogos/" + String(vid.SiteID) + ".png")

if vid.VideoID == 0 {
cell.ReleaseImage.alpha = 0.5
} else {
cell.ReleaseImage.alpha = 1.0
}

indexPathItem = -1
indexPathItem = indexPath.item
debugPrint(indexPathItem)

cell.TagsView.delegate = self
cell.TagsView.dataSource = self
return cell
}


and for populating the TableView



extension MiscCollectionViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if indexPathItem != -1 {
return Video[indexPathItem].Tags.count
} else {
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tags = tableView.dequeueReusableCell(withIdentifier: "Tag", for: indexPath) as! TagTableViewCell
debugPrint(String(indexPathItem) + " " + Video[indexPathItem].Tags[indexPath.row])
tags.TagLabel.text = String(indexPathItem) //Video[indexPathItem].Tags[indexPath.row]

return tags
}
}









share|improve this question

























  • How many collection view cells are there? Because if the number is fixed and less, I would recommend using a few views instead of a collection view.

    – Damon
    Nov 23 '18 at 19:14











  • @Damon It can be up to 500 depending on the result set from the database

    – Tom
    Nov 23 '18 at 19:15











  • Try tableview.reload() before the return cell statement of the Collection View's cellForItemAt method.

    – Damon
    Nov 23 '18 at 19:17













  • @Damon it won't build if I put it in the func collectionView or did you mean the tableview?

    – Tom
    Nov 23 '18 at 19:21













  • @Damon - update added cell.TagsView.reloadData() before the return cell and got the same result unfortunately. Interestingly though, the number of rows being returned seem to be correct. It is just the values of the rows that are wrong

    – Tom
    Nov 23 '18 at 19:32
















0















I'm trying to embed a UITableView into a UICollectionViewCell. I'm managing to get everything to load. However, when it does load it up it seems to randomly use the last loaded value for the UITableView List Items. My DebugPrint Output seems to load all of the CollectionViewCells before even referencing the TableView. Once the CollectionViewCells are set, then it populates the TableView with whatever value it is left with. How can I resolve this so that I'm using the correct values? I suspect it is something to how I'm using IndexPath however I'm fairly new to Swift.



Example WireFrame



Populating UICollectionView



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: releaseIdentifier, for: indexPath) as! ReleaseCollectionViewCell

let vid: VideoItem
vid = Video[indexPath.item]

let rating = vid.Rating
let denominator = 2.0
let roundedRating = round(rating*denominator )/denominator

if vid.SiteVideoID != 0 {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/sitePictures/(GetFilePath(ID: String(vid.SiteVideoID)))/(String(vid.SiteVideoID)).jpg")
} else {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/pictures/(GetFilePath(ID: String(vid.VideoID)))/(String(vid.VideoID))_001.png")
}

cell.ReleaseDate.text = vid.ReleaseDate
cell.ReleaseTitle.text = vid.Title

cell.SiteLogo.setImageFromURl(stringImageUrl: "(file.BaseURL)/siteLogos/" + String(vid.SiteID) + ".png")

if vid.VideoID == 0 {
cell.ReleaseImage.alpha = 0.5
} else {
cell.ReleaseImage.alpha = 1.0
}

indexPathItem = -1
indexPathItem = indexPath.item
debugPrint(indexPathItem)

cell.TagsView.delegate = self
cell.TagsView.dataSource = self
return cell
}


and for populating the TableView



extension MiscCollectionViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if indexPathItem != -1 {
return Video[indexPathItem].Tags.count
} else {
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tags = tableView.dequeueReusableCell(withIdentifier: "Tag", for: indexPath) as! TagTableViewCell
debugPrint(String(indexPathItem) + " " + Video[indexPathItem].Tags[indexPath.row])
tags.TagLabel.text = String(indexPathItem) //Video[indexPathItem].Tags[indexPath.row]

return tags
}
}









share|improve this question

























  • How many collection view cells are there? Because if the number is fixed and less, I would recommend using a few views instead of a collection view.

    – Damon
    Nov 23 '18 at 19:14











  • @Damon It can be up to 500 depending on the result set from the database

    – Tom
    Nov 23 '18 at 19:15











  • Try tableview.reload() before the return cell statement of the Collection View's cellForItemAt method.

    – Damon
    Nov 23 '18 at 19:17













  • @Damon it won't build if I put it in the func collectionView or did you mean the tableview?

    – Tom
    Nov 23 '18 at 19:21













  • @Damon - update added cell.TagsView.reloadData() before the return cell and got the same result unfortunately. Interestingly though, the number of rows being returned seem to be correct. It is just the values of the rows that are wrong

    – Tom
    Nov 23 '18 at 19:32














0












0








0








I'm trying to embed a UITableView into a UICollectionViewCell. I'm managing to get everything to load. However, when it does load it up it seems to randomly use the last loaded value for the UITableView List Items. My DebugPrint Output seems to load all of the CollectionViewCells before even referencing the TableView. Once the CollectionViewCells are set, then it populates the TableView with whatever value it is left with. How can I resolve this so that I'm using the correct values? I suspect it is something to how I'm using IndexPath however I'm fairly new to Swift.



Example WireFrame



Populating UICollectionView



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: releaseIdentifier, for: indexPath) as! ReleaseCollectionViewCell

let vid: VideoItem
vid = Video[indexPath.item]

let rating = vid.Rating
let denominator = 2.0
let roundedRating = round(rating*denominator )/denominator

if vid.SiteVideoID != 0 {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/sitePictures/(GetFilePath(ID: String(vid.SiteVideoID)))/(String(vid.SiteVideoID)).jpg")
} else {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/pictures/(GetFilePath(ID: String(vid.VideoID)))/(String(vid.VideoID))_001.png")
}

cell.ReleaseDate.text = vid.ReleaseDate
cell.ReleaseTitle.text = vid.Title

cell.SiteLogo.setImageFromURl(stringImageUrl: "(file.BaseURL)/siteLogos/" + String(vid.SiteID) + ".png")

if vid.VideoID == 0 {
cell.ReleaseImage.alpha = 0.5
} else {
cell.ReleaseImage.alpha = 1.0
}

indexPathItem = -1
indexPathItem = indexPath.item
debugPrint(indexPathItem)

cell.TagsView.delegate = self
cell.TagsView.dataSource = self
return cell
}


and for populating the TableView



extension MiscCollectionViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if indexPathItem != -1 {
return Video[indexPathItem].Tags.count
} else {
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tags = tableView.dequeueReusableCell(withIdentifier: "Tag", for: indexPath) as! TagTableViewCell
debugPrint(String(indexPathItem) + " " + Video[indexPathItem].Tags[indexPath.row])
tags.TagLabel.text = String(indexPathItem) //Video[indexPathItem].Tags[indexPath.row]

return tags
}
}









share|improve this question
















I'm trying to embed a UITableView into a UICollectionViewCell. I'm managing to get everything to load. However, when it does load it up it seems to randomly use the last loaded value for the UITableView List Items. My DebugPrint Output seems to load all of the CollectionViewCells before even referencing the TableView. Once the CollectionViewCells are set, then it populates the TableView with whatever value it is left with. How can I resolve this so that I'm using the correct values? I suspect it is something to how I'm using IndexPath however I'm fairly new to Swift.



Example WireFrame



Populating UICollectionView



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: releaseIdentifier, for: indexPath) as! ReleaseCollectionViewCell

let vid: VideoItem
vid = Video[indexPath.item]

let rating = vid.Rating
let denominator = 2.0
let roundedRating = round(rating*denominator )/denominator

if vid.SiteVideoID != 0 {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/sitePictures/(GetFilePath(ID: String(vid.SiteVideoID)))/(String(vid.SiteVideoID)).jpg")
} else {
cell.ReleaseImage.setImageFromURl(stringImageUrl: "(file.BaseURL)/pictures/(GetFilePath(ID: String(vid.VideoID)))/(String(vid.VideoID))_001.png")
}

cell.ReleaseDate.text = vid.ReleaseDate
cell.ReleaseTitle.text = vid.Title

cell.SiteLogo.setImageFromURl(stringImageUrl: "(file.BaseURL)/siteLogos/" + String(vid.SiteID) + ".png")

if vid.VideoID == 0 {
cell.ReleaseImage.alpha = 0.5
} else {
cell.ReleaseImage.alpha = 1.0
}

indexPathItem = -1
indexPathItem = indexPath.item
debugPrint(indexPathItem)

cell.TagsView.delegate = self
cell.TagsView.dataSource = self
return cell
}


and for populating the TableView



extension MiscCollectionViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if indexPathItem != -1 {
return Video[indexPathItem].Tags.count
} else {
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tags = tableView.dequeueReusableCell(withIdentifier: "Tag", for: indexPath) as! TagTableViewCell
debugPrint(String(indexPathItem) + " " + Video[indexPathItem].Tags[indexPath.row])
tags.TagLabel.text = String(indexPathItem) //Video[indexPathItem].Tags[indexPath.row]

return tags
}
}






ios swift uitableview uicollectionview uicollectionviewcell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 19:17









Damon

5201318




5201318










asked Nov 23 '18 at 18:59









TomTom

6,16011841




6,16011841













  • How many collection view cells are there? Because if the number is fixed and less, I would recommend using a few views instead of a collection view.

    – Damon
    Nov 23 '18 at 19:14











  • @Damon It can be up to 500 depending on the result set from the database

    – Tom
    Nov 23 '18 at 19:15











  • Try tableview.reload() before the return cell statement of the Collection View's cellForItemAt method.

    – Damon
    Nov 23 '18 at 19:17













  • @Damon it won't build if I put it in the func collectionView or did you mean the tableview?

    – Tom
    Nov 23 '18 at 19:21













  • @Damon - update added cell.TagsView.reloadData() before the return cell and got the same result unfortunately. Interestingly though, the number of rows being returned seem to be correct. It is just the values of the rows that are wrong

    – Tom
    Nov 23 '18 at 19:32



















  • How many collection view cells are there? Because if the number is fixed and less, I would recommend using a few views instead of a collection view.

    – Damon
    Nov 23 '18 at 19:14











  • @Damon It can be up to 500 depending on the result set from the database

    – Tom
    Nov 23 '18 at 19:15











  • Try tableview.reload() before the return cell statement of the Collection View's cellForItemAt method.

    – Damon
    Nov 23 '18 at 19:17













  • @Damon it won't build if I put it in the func collectionView or did you mean the tableview?

    – Tom
    Nov 23 '18 at 19:21













  • @Damon - update added cell.TagsView.reloadData() before the return cell and got the same result unfortunately. Interestingly though, the number of rows being returned seem to be correct. It is just the values of the rows that are wrong

    – Tom
    Nov 23 '18 at 19:32

















How many collection view cells are there? Because if the number is fixed and less, I would recommend using a few views instead of a collection view.

– Damon
Nov 23 '18 at 19:14





How many collection view cells are there? Because if the number is fixed and less, I would recommend using a few views instead of a collection view.

– Damon
Nov 23 '18 at 19:14













@Damon It can be up to 500 depending on the result set from the database

– Tom
Nov 23 '18 at 19:15





@Damon It can be up to 500 depending on the result set from the database

– Tom
Nov 23 '18 at 19:15













Try tableview.reload() before the return cell statement of the Collection View's cellForItemAt method.

– Damon
Nov 23 '18 at 19:17







Try tableview.reload() before the return cell statement of the Collection View's cellForItemAt method.

– Damon
Nov 23 '18 at 19:17















@Damon it won't build if I put it in the func collectionView or did you mean the tableview?

– Tom
Nov 23 '18 at 19:21







@Damon it won't build if I put it in the func collectionView or did you mean the tableview?

– Tom
Nov 23 '18 at 19:21















@Damon - update added cell.TagsView.reloadData() before the return cell and got the same result unfortunately. Interestingly though, the number of rows being returned seem to be correct. It is just the values of the rows that are wrong

– Tom
Nov 23 '18 at 19:32





@Damon - update added cell.TagsView.reloadData() before the return cell and got the same result unfortunately. Interestingly though, the number of rows being returned seem to be correct. It is just the values of the rows that are wrong

– Tom
Nov 23 '18 at 19:32












0






active

oldest

votes











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%2f53451771%2fadding-a-uitableview-to-a-uicollectionviewcell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53451771%2fadding-a-uitableview-to-a-uicollectionviewcell%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

Wiesbaden

Marschland

Dieringhausen