Adding a uiview on a uiview in uitableviewcell












0















I am passing a view to UITableViewCell from cellForForAtIndex method. I want cell to resize based upon the content of UIView but cell's height is not changing. I have tried to add constraint from coding when I add custom view.
UITableViewCell method:



func addContainerView(view:UIView){
vwContainer.addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: view, attribute: .leading, relatedBy: .equal, toItem: vwContainer, attribute: .leading, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: .equal, toItem: vwContainer, attribute: .trailing, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: vwContainer, attribute: .top, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: vwContainer, attribute: .bottom, multiplier: 1.0, constant: 0.0).isActive = true
}


Above code is called from the following code in CellForRowAtIndex:



if let rowObj = objData?.itemsArray?[indexPath.row] as? TableViewDataFormat, let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell, for: indexPath) as? HiltiTableViewCell {
if let container = rowObj.containerview{
cell.addContainerView(view: container)
cell.lblTitle.text = rowObj.cellTitle
}
return cell
}


The objective here is to create a custom uitableview in a custom framework where I can pass a UIView and cell should resize based upon the content of the view passed in.



Edit 1:
Tried to add content over contentview like following:
cell.contentView.addSubview(container)
but still getting an overlapped view as follows:
enter image description here



It should have bee 3 different cells, first one with uiview and other 2 with image inside










share|improve this question

























  • You're adding a view on top of the cell, why you expect the cell height to change?

    – Tal Cohen
    Nov 25 '18 at 8:35











  • I tried to add it to content also but still, views are overlapping

    – pankaj
    Nov 25 '18 at 8:44











  • The code you wrote is for overlapping views.

    – Tal Cohen
    Nov 25 '18 at 8:47











  • Try to use StackView and add to view to it. Remember to remove this view on prepareForReuse, because it will be added again and again.

    – Tal Cohen
    Nov 25 '18 at 8:48











  • I can't use stackview here, as there will be a different kind of tablecell here. In addition to custom view, I will also have the option to create a cell on the basis of few predefined templates.

    – pankaj
    Nov 25 '18 at 8:51
















0















I am passing a view to UITableViewCell from cellForForAtIndex method. I want cell to resize based upon the content of UIView but cell's height is not changing. I have tried to add constraint from coding when I add custom view.
UITableViewCell method:



func addContainerView(view:UIView){
vwContainer.addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: view, attribute: .leading, relatedBy: .equal, toItem: vwContainer, attribute: .leading, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: .equal, toItem: vwContainer, attribute: .trailing, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: vwContainer, attribute: .top, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: vwContainer, attribute: .bottom, multiplier: 1.0, constant: 0.0).isActive = true
}


Above code is called from the following code in CellForRowAtIndex:



if let rowObj = objData?.itemsArray?[indexPath.row] as? TableViewDataFormat, let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell, for: indexPath) as? HiltiTableViewCell {
if let container = rowObj.containerview{
cell.addContainerView(view: container)
cell.lblTitle.text = rowObj.cellTitle
}
return cell
}


The objective here is to create a custom uitableview in a custom framework where I can pass a UIView and cell should resize based upon the content of the view passed in.



Edit 1:
Tried to add content over contentview like following:
cell.contentView.addSubview(container)
but still getting an overlapped view as follows:
enter image description here



It should have bee 3 different cells, first one with uiview and other 2 with image inside










share|improve this question

























  • You're adding a view on top of the cell, why you expect the cell height to change?

    – Tal Cohen
    Nov 25 '18 at 8:35











  • I tried to add it to content also but still, views are overlapping

    – pankaj
    Nov 25 '18 at 8:44











  • The code you wrote is for overlapping views.

    – Tal Cohen
    Nov 25 '18 at 8:47











  • Try to use StackView and add to view to it. Remember to remove this view on prepareForReuse, because it will be added again and again.

    – Tal Cohen
    Nov 25 '18 at 8:48











  • I can't use stackview here, as there will be a different kind of tablecell here. In addition to custom view, I will also have the option to create a cell on the basis of few predefined templates.

    – pankaj
    Nov 25 '18 at 8:51














0












0








0








I am passing a view to UITableViewCell from cellForForAtIndex method. I want cell to resize based upon the content of UIView but cell's height is not changing. I have tried to add constraint from coding when I add custom view.
UITableViewCell method:



func addContainerView(view:UIView){
vwContainer.addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: view, attribute: .leading, relatedBy: .equal, toItem: vwContainer, attribute: .leading, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: .equal, toItem: vwContainer, attribute: .trailing, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: vwContainer, attribute: .top, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: vwContainer, attribute: .bottom, multiplier: 1.0, constant: 0.0).isActive = true
}


Above code is called from the following code in CellForRowAtIndex:



if let rowObj = objData?.itemsArray?[indexPath.row] as? TableViewDataFormat, let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell, for: indexPath) as? HiltiTableViewCell {
if let container = rowObj.containerview{
cell.addContainerView(view: container)
cell.lblTitle.text = rowObj.cellTitle
}
return cell
}


The objective here is to create a custom uitableview in a custom framework where I can pass a UIView and cell should resize based upon the content of the view passed in.



Edit 1:
Tried to add content over contentview like following:
cell.contentView.addSubview(container)
but still getting an overlapped view as follows:
enter image description here



It should have bee 3 different cells, first one with uiview and other 2 with image inside










share|improve this question
















I am passing a view to UITableViewCell from cellForForAtIndex method. I want cell to resize based upon the content of UIView but cell's height is not changing. I have tried to add constraint from coding when I add custom view.
UITableViewCell method:



func addContainerView(view:UIView){
vwContainer.addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: view, attribute: .leading, relatedBy: .equal, toItem: vwContainer, attribute: .leading, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: .equal, toItem: vwContainer, attribute: .trailing, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: vwContainer, attribute: .top, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: vwContainer, attribute: .bottom, multiplier: 1.0, constant: 0.0).isActive = true
}


Above code is called from the following code in CellForRowAtIndex:



if let rowObj = objData?.itemsArray?[indexPath.row] as? TableViewDataFormat, let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell, for: indexPath) as? HiltiTableViewCell {
if let container = rowObj.containerview{
cell.addContainerView(view: container)
cell.lblTitle.text = rowObj.cellTitle
}
return cell
}


The objective here is to create a custom uitableview in a custom framework where I can pass a UIView and cell should resize based upon the content of the view passed in.



Edit 1:
Tried to add content over contentview like following:
cell.contentView.addSubview(container)
but still getting an overlapped view as follows:
enter image description here



It should have bee 3 different cells, first one with uiview and other 2 with image inside







ios swift uitableview uiview autolayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 8:47







pankaj

















asked Nov 25 '18 at 8:33









pankajpankaj

2,731125396




2,731125396













  • You're adding a view on top of the cell, why you expect the cell height to change?

    – Tal Cohen
    Nov 25 '18 at 8:35











  • I tried to add it to content also but still, views are overlapping

    – pankaj
    Nov 25 '18 at 8:44











  • The code you wrote is for overlapping views.

    – Tal Cohen
    Nov 25 '18 at 8:47











  • Try to use StackView and add to view to it. Remember to remove this view on prepareForReuse, because it will be added again and again.

    – Tal Cohen
    Nov 25 '18 at 8:48











  • I can't use stackview here, as there will be a different kind of tablecell here. In addition to custom view, I will also have the option to create a cell on the basis of few predefined templates.

    – pankaj
    Nov 25 '18 at 8:51



















  • You're adding a view on top of the cell, why you expect the cell height to change?

    – Tal Cohen
    Nov 25 '18 at 8:35











  • I tried to add it to content also but still, views are overlapping

    – pankaj
    Nov 25 '18 at 8:44











  • The code you wrote is for overlapping views.

    – Tal Cohen
    Nov 25 '18 at 8:47











  • Try to use StackView and add to view to it. Remember to remove this view on prepareForReuse, because it will be added again and again.

    – Tal Cohen
    Nov 25 '18 at 8:48











  • I can't use stackview here, as there will be a different kind of tablecell here. In addition to custom view, I will also have the option to create a cell on the basis of few predefined templates.

    – pankaj
    Nov 25 '18 at 8:51

















You're adding a view on top of the cell, why you expect the cell height to change?

– Tal Cohen
Nov 25 '18 at 8:35





You're adding a view on top of the cell, why you expect the cell height to change?

– Tal Cohen
Nov 25 '18 at 8:35













I tried to add it to content also but still, views are overlapping

– pankaj
Nov 25 '18 at 8:44





I tried to add it to content also but still, views are overlapping

– pankaj
Nov 25 '18 at 8:44













The code you wrote is for overlapping views.

– Tal Cohen
Nov 25 '18 at 8:47





The code you wrote is for overlapping views.

– Tal Cohen
Nov 25 '18 at 8:47













Try to use StackView and add to view to it. Remember to remove this view on prepareForReuse, because it will be added again and again.

– Tal Cohen
Nov 25 '18 at 8:48





Try to use StackView and add to view to it. Remember to remove this view on prepareForReuse, because it will be added again and again.

– Tal Cohen
Nov 25 '18 at 8:48













I can't use stackview here, as there will be a different kind of tablecell here. In addition to custom view, I will also have the option to create a cell on the basis of few predefined templates.

– pankaj
Nov 25 '18 at 8:51





I can't use stackview here, as there will be a different kind of tablecell here. In addition to custom view, I will also have the option to create a cell on the basis of few predefined templates.

– pankaj
Nov 25 '18 at 8:51












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%2f53465856%2fadding-a-uiview-on-a-uiview-in-uitableviewcell%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%2f53465856%2fadding-a-uiview-on-a-uiview-in-uitableviewcell%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

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Fotorealismo