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.
ios swift xcode
add a comment |
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.
ios swift xcode
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 settableview.delegate
?
– Ratul Sharker
Nov 7 at 9:07
add a comment |
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.
ios swift xcode
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
ios swift xcode
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 settableview.delegate
?
– Ratul Sharker
Nov 7 at 9:07
add a comment |
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 settableview.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
add a comment |
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.
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 yourshopImagesViewCell
class object ?
– Ratul Sharker
Nov 7 at 7:23
do your delegatetableView 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 thetableView.delegate
?
– Ratul Sharker
Nov 7 at 9:08
|
show 1 more comment
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.
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 yourshopImagesViewCell
class object ?
– Ratul Sharker
Nov 7 at 7:23
do your delegatetableView 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 thetableView.delegate
?
– Ratul Sharker
Nov 7 at 9:08
|
show 1 more comment
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.
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 yourshopImagesViewCell
class object ?
– Ratul Sharker
Nov 7 at 7:23
do your delegatetableView 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 thetableView.delegate
?
– Ratul Sharker
Nov 7 at 9:08
|
show 1 more comment
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.
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.
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 yourshopImagesViewCell
class object ?
– Ratul Sharker
Nov 7 at 7:23
do your delegatetableView 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 thetableView.delegate
?
– Ratul Sharker
Nov 7 at 9:08
|
show 1 more comment
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 yourshopImagesViewCell
class object ?
– Ratul Sharker
Nov 7 at 7:23
do your delegatetableView 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 thetableView.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
|
show 1 more comment
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
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
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
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
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
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