I have added a UIView on top of a tableviewcontroller
in IB by dragging and dropping then I have assigned and IBoutlet
to that UIView
.
Problem is I have a uilabel that is dynamically changing its size , so if uilabel is short I want to make the tableview closer otherwise tableview should be not that close so I can show a very long label.
So I try to change the frame of the uiview
that is on top of tableview
uiview changes its frame size but tableview stays stable there.
I wan to make uitableview
go down when I make UIview
frame size height bigger
if ([[self agenda] getMeetingTime] != nil) {
descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, dateLabel.frame.origin.y + dateLabel.bounds.size.height+15, self.view.frame.size.width-75, 150)];
descriptionLabel.textColor =[UIColor colorWithRed:96/256.0 green:96/256.0 blue:96/256.0 alpha:1.0];
descriptionLabel.font = [UIFont fontWithName:@"GillSans" size:15.0f];
descriptionLabel.text =[[self agenda] getMeetingTime];
descriptionLabel.backgroundColor = [UIColor clearColor];
descriptionLabel.numberOfLines=0;
descriptionLabel.tag=PopulateTag;
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(709,999);
CGSize expectedLabelSize = [descriptionLabel.text sizeWithFont:descriptionLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:descriptionLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = descriptionLabel.frame;
newFrame.size.height = expectedLabelSize.height;
descriptionLabel.frame=newFrame;
if ( expectedLabelSize.height>70) {
self.upperView.frame = CGRectMake(0, 0, self.upperView.frame.size.width, self.upperView.frame.size.height+expectedLabelSize.height+20);
}
else
{
self.upperView.frame = CGRectMake(0, 0, self.upperView.frame.size.width, self.upperView.frame.size.height+expectedLabelSize.height);
}
[ self.upperView addSubview: descriptionLabel];
}
//black line
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, descriptionLabel.frame.origin.y + descriptionLabel.bounds.size.height+15, descriptionLabel.frame.size.width+50, 1)];
line.backgroundColor=[UIColor colorWithRed:164/256.0 green:165/256.0 blue:160/256.0 alpha:1.0];
line.tag=PopulateTag;
[self.upperView addSubview:line];
//this does not work pushes whole view down
//self.restOfView.frame=CGRectMake(10, line.frame.origin.y + line.bounds.size.height+1, self.upperView.frame.size.width, 600);
[restOfView reloadData];
On IB:
This is what happens:
Tableview needs go down here
How can I solve this problem?
Firstly, I don't believe you should be subclassing a UITableViewController
to achieve what you want. A UITableViewController
is useful when you know that your view will only contain a UITableView
, in my opinion adding anything else to one defeats the purpose.
To solve your problem though, in the bottom of your code snippet uncomment out the line where you change the frame of your tableview (assuming self.restOfView
is your tableView) and instead of call [self.restOfView reloadData]
call:
[self.restOfView setNeedsDisplay];
reloadData
just calls the tableView data source methods again, setNeedsDisplay
redraws the object. I think that will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.