Answer the question
In order to leave comments, you need to log in
How to programmatically change the width of a UITableView?
Hello.
In general, there is a UIViewController in which I placed a UITableView in full screen (main UIView). iPad. I use a storyboard.
There is a task: when an entry is selected in a UITableView, the size and position of the UItableView should change (the width decreases, and the view itself shifts to the right). And a view (or without it) with the details of the selected record should be displayed on the left.
I tried to do it in the following way:
Controller code:
- (void)viewDidLoad {
[super viewDidLoad];
bigFrame = self.tableView.frame;
CGFloat xOffset = 256;
smallFrame = CGRectMake(bigFrame.origin.x + xOffset, bigFrame.origin.y, bigFrame.size.width - xOffset, bigFrame.size.height);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
tableView.frame = smallFrame;
}
Answer the question
In order to leave comments, you need to log in
You can move the tableView Leading Space to Superview to Outlet, and change it
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.leftSpace.constant = 256;
[UIView animateWithDuration:animationDuration animations:^
{
[self.view layoutIfNeeded];
}];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.leftSpace.constant = 0;
[UIView animateWithDuration:animationDuration animations:^
{
[self.view layoutIfNeeded];
}];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question