Reputation: 1608
I'm using a custom UITableViewCell I've created to expand a cell when it's touched. I do this using beginUpdates/endUpdates, which in turn call heightForRowAtIndexPath. It works fine, the cell expands, the label I have on it displays. All good so far.
The only issue is the UITableView itself isn't resizing to account for the extra height of the cell.
I've read about resizing the frame, but it doesn't seem to work. Does anyone know how I can do this, because it feels like it should be pretty simple!
Upvotes: 0
Views: 719
Reputation: 462
If I understand your issue correctly, I believe I ran into the same problem recently. I found the answer in a macheads 101 tutorial on youtube. His example dealt with a UITableView that resized itself to account for a keyboard display.
[[NSNotificationCenter defaultCenter] addObserver:self selector:
@selector(keyBoardHidden:) name:UIKeyboardWillHideNotification object:nil];
this is in the viewDidLoad method and it calls keyBoardHidden which looks like this:
- (void)keyBoardHidden:(NSNotification *)note {
//[[self tableView:tableView cellForRowAtIndexPath:0].textLabel setText:@""];
//[tableView setFrame:self.view.bounds];
CGRect searchBarFrame = searchBar.frame;
CGRect newTableViewFrame = CGRectMake (0, (float)searchBarFrame.size.height,
320, 480);
[tableView setFrame:newTableViewFrame];
}
He resized the frame with the simple command [tableView setFrame:self.view.bounds]; but that left the top cell hidden by the search bar, which I originally solved by just blanking out the first cell, but I then decided that was bush league and told the UITableView frame to start at the bottom of the search bar. I left the other solution in comments though in case it is useful to you.
Unfortunately this is only an example. I am not knowledgable enough to be able to tell you where to implement these techniques in your code. I hope that this is somehow useful anyway.
Upvotes: 1
Reputation: 11174
I've never tried this but I would say you shouldn't be resizing the table view size, its a scroll view so you should be adjusting the contentSize property
Upvotes: 0