How to set the vertical length of xib as code in Swift











up vote
2
down vote

favorite












I would like to modify the height of the View in Xib Size Inspector flexibly in the code.



I also want to modify the Height Equals in Constraints in the UICollectionView in Xib.



Short Code :



class ShopImagesViewCell: UITableViewCell
{
@IBOutlet weak var imageCollectionView: UICollectionView!

override func awakeFromNib()
{
super.awakeFromNib()
// ......
}
}

extension ShopImagesViewCell
{
func setView(urls : [String], isZzip : Bool)
{
self.imageCollectionView.delegate = self
self.imageCollectionView.dataSource = self
self.imageCollectionView.regCells(cells:
["ShopImageCollectionViewCell","ShopNonImageCollectionViewCell"])
// ......
}
}

extension ShopImagesViewCell : UICollectionViewDelegateFlowLayout, UITableViewDelegate
{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return CGFloat(291) // It does not work.
}
}


When Xib is first loaded, it is executed only once to fit in size.



Modifying Xib height length in code and modifying the Height Equals of Constraintsd in UICollectionView in code.



Please tell me where I should use the code.










share|improve this question
























  • Where is the code adjusting the height? Also, if you are using auto layout, it is a best practice to not adjust the frame.
    – Skywalker
    Nov 7 at 2:42










  • where is your code to set tableview.delegate ?
    – Ratul Sharker
    Nov 7 at 9:07















up vote
2
down vote

favorite












I would like to modify the height of the View in Xib Size Inspector flexibly in the code.



I also want to modify the Height Equals in Constraints in the UICollectionView in Xib.



Short Code :



class ShopImagesViewCell: UITableViewCell
{
@IBOutlet weak var imageCollectionView: UICollectionView!

override func awakeFromNib()
{
super.awakeFromNib()
// ......
}
}

extension ShopImagesViewCell
{
func setView(urls : [String], isZzip : Bool)
{
self.imageCollectionView.delegate = self
self.imageCollectionView.dataSource = self
self.imageCollectionView.regCells(cells:
["ShopImageCollectionViewCell","ShopNonImageCollectionViewCell"])
// ......
}
}

extension ShopImagesViewCell : UICollectionViewDelegateFlowLayout, UITableViewDelegate
{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return CGFloat(291) // It does not work.
}
}


When Xib is first loaded, it is executed only once to fit in size.



Modifying Xib height length in code and modifying the Height Equals of Constraintsd in UICollectionView in code.



Please tell me where I should use the code.










share|improve this question
























  • Where is the code adjusting the height? Also, if you are using auto layout, it is a best practice to not adjust the frame.
    – Skywalker
    Nov 7 at 2:42










  • where is your code to set tableview.delegate ?
    – Ratul Sharker
    Nov 7 at 9:07













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I would like to modify the height of the View in Xib Size Inspector flexibly in the code.



I also want to modify the Height Equals in Constraints in the UICollectionView in Xib.



Short Code :



class ShopImagesViewCell: UITableViewCell
{
@IBOutlet weak var imageCollectionView: UICollectionView!

override func awakeFromNib()
{
super.awakeFromNib()
// ......
}
}

extension ShopImagesViewCell
{
func setView(urls : [String], isZzip : Bool)
{
self.imageCollectionView.delegate = self
self.imageCollectionView.dataSource = self
self.imageCollectionView.regCells(cells:
["ShopImageCollectionViewCell","ShopNonImageCollectionViewCell"])
// ......
}
}

extension ShopImagesViewCell : UICollectionViewDelegateFlowLayout, UITableViewDelegate
{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return CGFloat(291) // It does not work.
}
}


When Xib is first loaded, it is executed only once to fit in size.



Modifying Xib height length in code and modifying the Height Equals of Constraintsd in UICollectionView in code.



Please tell me where I should use the code.










share|improve this question















I would like to modify the height of the View in Xib Size Inspector flexibly in the code.



I also want to modify the Height Equals in Constraints in the UICollectionView in Xib.



Short Code :



class ShopImagesViewCell: UITableViewCell
{
@IBOutlet weak var imageCollectionView: UICollectionView!

override func awakeFromNib()
{
super.awakeFromNib()
// ......
}
}

extension ShopImagesViewCell
{
func setView(urls : [String], isZzip : Bool)
{
self.imageCollectionView.delegate = self
self.imageCollectionView.dataSource = self
self.imageCollectionView.regCells(cells:
["ShopImageCollectionViewCell","ShopNonImageCollectionViewCell"])
// ......
}
}

extension ShopImagesViewCell : UICollectionViewDelegateFlowLayout, UITableViewDelegate
{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return CGFloat(291) // It does not work.
}
}


When Xib is first loaded, it is executed only once to fit in size.



Modifying Xib height length in code and modifying the Height Equals of Constraintsd in UICollectionView in code.



Please tell me where I should use the code.







ios swift xcode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 7:52

























asked Nov 7 at 2:19









Enkha

1016




1016












  • Where is the code adjusting the height? Also, if you are using auto layout, it is a best practice to not adjust the frame.
    – Skywalker
    Nov 7 at 2:42










  • where is your code to set tableview.delegate ?
    – Ratul Sharker
    Nov 7 at 9:07


















  • Where is the code adjusting the height? Also, if you are using auto layout, it is a best practice to not adjust the frame.
    – Skywalker
    Nov 7 at 2:42










  • where is your code to set tableview.delegate ?
    – Ratul Sharker
    Nov 7 at 9:07
















Where is the code adjusting the height? Also, if you are using auto layout, it is a best practice to not adjust the frame.
– Skywalker
Nov 7 at 2:42




Where is the code adjusting the height? Also, if you are using auto layout, it is a best practice to not adjust the frame.
– Skywalker
Nov 7 at 2:42












where is your code to set tableview.delegate ?
– Ratul Sharker
Nov 7 at 9:07




where is your code to set tableview.delegate ?
– Ratul Sharker
Nov 7 at 9:07












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










According to you pasted code, it seems that you placed a custom UITableViewCell into the nib. Assumed on that, you cannot set height directly without the help of UITableViewDelegate.



Where the UITableViewDelegate is implemented or you intended to implement add this delegate method



 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// you have the indexPath based on which you can set the height dynamically, based on the cell position.
// return your intended height here
}


Hope it helps.






share|improve this answer





















  • extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
    – Enkha
    Nov 7 at 7:19










  • did you set tableview.delegate to your shopImagesViewCell class object ?
    – Ratul Sharker
    Nov 7 at 7:23












  • do your delegate tableView heightForRowAtIndexPath get even called
    – Ratul Sharker
    Nov 7 at 7:33










  • I have modified my code. Please take a look.
    – Enkha
    Nov 7 at 8:00










  • in your updated question, where is the code which set the tableView.delegate ?
    – Ratul Sharker
    Nov 7 at 9:08











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',
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%2f53182788%2fhow-to-set-the-vertical-length-of-xib-as-code-in-swift%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










According to you pasted code, it seems that you placed a custom UITableViewCell into the nib. Assumed on that, you cannot set height directly without the help of UITableViewDelegate.



Where the UITableViewDelegate is implemented or you intended to implement add this delegate method



 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// you have the indexPath based on which you can set the height dynamically, based on the cell position.
// return your intended height here
}


Hope it helps.






share|improve this answer





















  • extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
    – Enkha
    Nov 7 at 7:19










  • did you set tableview.delegate to your shopImagesViewCell class object ?
    – Ratul Sharker
    Nov 7 at 7:23












  • do your delegate tableView heightForRowAtIndexPath get even called
    – Ratul Sharker
    Nov 7 at 7:33










  • I have modified my code. Please take a look.
    – Enkha
    Nov 7 at 8:00










  • in your updated question, where is the code which set the tableView.delegate ?
    – Ratul Sharker
    Nov 7 at 9:08















up vote
2
down vote



accepted










According to you pasted code, it seems that you placed a custom UITableViewCell into the nib. Assumed on that, you cannot set height directly without the help of UITableViewDelegate.



Where the UITableViewDelegate is implemented or you intended to implement add this delegate method



 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// you have the indexPath based on which you can set the height dynamically, based on the cell position.
// return your intended height here
}


Hope it helps.






share|improve this answer





















  • extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
    – Enkha
    Nov 7 at 7:19










  • did you set tableview.delegate to your shopImagesViewCell class object ?
    – Ratul Sharker
    Nov 7 at 7:23












  • do your delegate tableView heightForRowAtIndexPath get even called
    – Ratul Sharker
    Nov 7 at 7:33










  • I have modified my code. Please take a look.
    – Enkha
    Nov 7 at 8:00










  • in your updated question, where is the code which set the tableView.delegate ?
    – Ratul Sharker
    Nov 7 at 9:08













up vote
2
down vote



accepted







up vote
2
down vote



accepted






According to you pasted code, it seems that you placed a custom UITableViewCell into the nib. Assumed on that, you cannot set height directly without the help of UITableViewDelegate.



Where the UITableViewDelegate is implemented or you intended to implement add this delegate method



 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// you have the indexPath based on which you can set the height dynamically, based on the cell position.
// return your intended height here
}


Hope it helps.






share|improve this answer












According to you pasted code, it seems that you placed a custom UITableViewCell into the nib. Assumed on that, you cannot set height directly without the help of UITableViewDelegate.



Where the UITableViewDelegate is implemented or you intended to implement add this delegate method



 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// you have the indexPath based on which you can set the height dynamically, based on the cell position.
// return your intended height here
}


Hope it helps.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 2:42









Ratul Sharker

2,04711524




2,04711524












  • extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
    – Enkha
    Nov 7 at 7:19










  • did you set tableview.delegate to your shopImagesViewCell class object ?
    – Ratul Sharker
    Nov 7 at 7:23












  • do your delegate tableView heightForRowAtIndexPath get even called
    – Ratul Sharker
    Nov 7 at 7:33










  • I have modified my code. Please take a look.
    – Enkha
    Nov 7 at 8:00










  • in your updated question, where is the code which set the tableView.delegate ?
    – Ratul Sharker
    Nov 7 at 9:08


















  • extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
    – Enkha
    Nov 7 at 7:19










  • did you set tableview.delegate to your shopImagesViewCell class object ?
    – Ratul Sharker
    Nov 7 at 7:23












  • do your delegate tableView heightForRowAtIndexPath get even called
    – Ratul Sharker
    Nov 7 at 7:33










  • I have modified my code. Please take a look.
    – Enkha
    Nov 7 at 8:00










  • in your updated question, where is the code which set the tableView.delegate ?
    – Ratul Sharker
    Nov 7 at 9:08
















extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
– Enkha
Nov 7 at 7:19




extension ShopImagesViewCell: UITableViewDelegate I paste and run the code but it does not work.
– Enkha
Nov 7 at 7:19












did you set tableview.delegate to your shopImagesViewCell class object ?
– Ratul Sharker
Nov 7 at 7:23






did you set tableview.delegate to your shopImagesViewCell class object ?
– Ratul Sharker
Nov 7 at 7:23














do your delegate tableView heightForRowAtIndexPath get even called
– Ratul Sharker
Nov 7 at 7:33




do your delegate tableView heightForRowAtIndexPath get even called
– Ratul Sharker
Nov 7 at 7:33












I have modified my code. Please take a look.
– Enkha
Nov 7 at 8:00




I have modified my code. Please take a look.
– Enkha
Nov 7 at 8:00












in your updated question, where is the code which set the tableView.delegate ?
– Ratul Sharker
Nov 7 at 9:08




in your updated question, where is the code which set the tableView.delegate ?
– Ratul Sharker
Nov 7 at 9:08


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53182788%2fhow-to-set-the-vertical-length-of-xib-as-code-in-swift%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()