Reputation: 418
Rookie in iOS. I have a Freeform ViewController, which has an UIImageView and UITableView in it.
The Problem i am facing here is when i try to scroll the tableview some of the items stay hidden because of the height it has taken in the freeform viewcontroller.
I tried the following code to set the UItableview's height programmatically according to the size of the screen.
let screenSize: CGRect = UIScreen.mainScreen().bounds
tableview.frame = CGRectMake(0,imageview.frame.height, 280, (screenSize.height -imageview.frame.height))
The above code failed to resize the tableview.
Is there any other way that i can set the UITableview size at Runtime or in the storyboard.
Solution
I resolved the issue after laid out my both views using custom height and width after specifying translatesAutoresizingMaskIntoConstraints = true for both the views. I did as per my design and app requirement.
Upvotes: 1
Views: 3864
Reputation: 21
There is a delegate function for the UITableViewCell
height.
Here you specify the indexPath of that particular cell and return your height for it
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == yourSection && indexPath.row == yourRow) {
return 140.0; //return height for required row
}
// "Else"
return someDefaultHeight;
}
Upvotes: 1
Reputation: 3663
Don't set Tableview height programmatically.
Just do one thing
Take Top, Bottom, Leading, Trailing constraints and set constant value to 0
Add user image view into tableview header.
Upvotes: 0
Reputation: 11817
if you are using auto layout or constraints, you have to
tableview.translatesAutoresizingMaskIntoConstraints = true
before applying the new frame, the new frame is not updating because it's getting over-riden by auto layout and constraints.
EDIT :
1- if you have [adjust scroll view insets] enabled in your view controller in story boards disable it, and test and see.
2- do you create the imageView programatically? or from interface builder, and do you have constraints on it?
3- did you know that the status bar has a height and you have to compensate for it too?
4- do you use a navigation bar?
Upvotes: 3