Reputation: 1581
I'm trying to shorten the height of my UITableView and put a button underneath. I tried using this code:
// set the frame size
CGRect frame = self.view.frame;
frame.size.height = 355;
self.view.frame = frame;
//set up the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(buttonPress:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Add to Current Workout" forState:UIControlStateNormal];
button.frame = CGRectMake(20, 365, 280, 40);
[self.view addSubview:button];
in the viewDidAppear method, but all that happens is the view gets shorter and when I scroll down the button is covering one of my cells (it also scrolls with the tableview). How can I change the height of the tableview and have a button underneath the view?
Upvotes: 0
Views: 2047
Reputation: 530
self.view returns "the view in which the touch initially occurred," according to the docs. To change the tableView, you will want to use self.tableView, which returns "the tableView managed by the controller object," assuming you're doing this in a TableViewController. Change the first and third line:
CGRect frame = self.tableView.frame;
frame.size.height = 355;
self.tableView.frame = frame;
To get the button to appear under the tableView, as per this question you can set it as the tableView's tableFooterView. So change the last line to:
self.tableView.tableFooterView = button;
Upvotes: 2
Reputation: 23634
You need to decrease the size of the table view, not your whole view (as you're currently doing).
Should be self.tableView.frame = frame
(where tableview is the name of your UITableView).
Upvotes: 0