I am writing an iOS app.
User types in movie search keywords and it fetches data from omdbapi.com and displays movies in tableview.
Issue is that that table view cell isn't getting displayed correctly.
Project URL:
project on onedrive
I tried using every autolayout method but, its not working.
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension;
}
You need to set estimate method for table height too. so place these method for height calculation and also check your cell constraint.
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Hope this will help you.
Related
I have a tableview. I created it from storyboard it is a static tableview.(I am using it for profile settings).
But i have to change height of the first row of this table view dynamically and i don't want to change other cell heights. They should use their storyboard height values. How can i do this?
I tried following code:
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 100
}
return (tableView.cellForRow(at: indexPath)?.bounds.height)!
}
But this is setting 100 for all cells.
My tableview:
Use the following override function..
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 100
}
return UITableView.automaticDimension
}
But you have to make sure that every item in the static tableview have (top/bottom/left/right) constraints. it only works when it have all these constraints on it.
I have a tableView cell with constrains that works nice in Xcode 9, and iOS 10, after upgrate to iOS 12 and Xcode 10 the self sizing stop working, tableView was unable to determinate the cell size.
The cell designing is this with all constraints:
So setting by code the automatic dimension
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 196
}
The result is that I have to use the height for row with a number instead of automaticDimension to see the cell in tableView. So, I'm missing a constrain here or what.
I wanna get like this:
I am using a custom UITableViewCell where I download images asynchronously with Alamofire from within the cell.
The images appear after the cell was loaded from within the UITableviewController.
Some images do not exist. So the cell should be collapsed and show only text if there is no image present.
How can I achieve to resize the cell when the image is present?
(All images should appear in the same height and full width.
What I already tried is something like this in my TableViewController:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
But the result is pretty ugly:
I am new to IOS and anyhow i have implemented the FZAccordion from HERE. Now my problem is when i have a long text in header section and cells it goes beyond the bounds.So how can i get rid of this problem so that no matter how long is the text it always fits in the screen.
Thank you.
You can use
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(_ tableView: UITableView,estimatedHeightForRowAtindexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension}
This will automatically resizes your text in your cells.
I am trying to have a UITableView with different sized prototype cells.
I set the row height in my Table View to 243. The first and second cells' individual row height are set to 243 and 465, respectively. When I run my app, both cells appear at 243 height.
Here is what I have tried:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 25
}
//does not change cell height
And:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 25
}
//Method does not override any method from its superclass
How can I configure my project to successfully resize the second cell?
The signature of the delegate method has changed in Swift 3. It needs to be:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 1 {
return 465.0
} else {
return 243.0
}
}
With the wrong signature the table view doesn't know you've implemented the method so it never gets called.