I have a UITableView populated with custom UITableViewCells. Within these user cells, I have a UITextField and UIButton Read More. The goal of UIButton is to dynamically expand this particular UITableCell when the user wants to read more text. Similarly, when the user wants to return to the original size, the user clicks the button again, and the UITableViewCell will be reduced to its original size.
Since no cell is selected, I configure IBAction inside the user cell, for example:
// Within CustomCell.m
- (IBAction)showMoreText:(id)sender
{
self.hasBeenResized = YES;
[[self.cellView layer] setMasksToBounds:NO];
CGRect newTextViewFrame = self.textView.frame;
newTextViewFrame.size.height = self.textView.contentSize.height;
self.textView.frame = newTextViewFrame;
CGFloat bottomYPos = self.textView.frame.origin.y + self.textView.frame.size.height;
CGRect buttonFrame = self.showMoreButton.frame;
buttonFrame.origin.y = bottomYPos;
self.showMoreButton.frame = buttonFrame;
[(UITableView*) self.superview beginUpdates];
[(UITableView*) self.superview endUpdates];
[[self.cellView layer] setMasksToBounds:YES];
[[self.cellView layer] setCornerRadius:10.0];
}
After that, I have this in my ViewController class:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"heightForRowAtIndexPath");
CustomCell *cell = (CustomCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
if([cell hasBeenResized] == NO)
{
return cell.frame.size.height + 20;
}
else
{
return cell.frame.size.height + cell.textView.frame.origin.y + cell.textView.frame.size.height + cell.showMoreButton.frame.size.height + 20;
}
}
, , . If-else, , hasBeenResized false, YES IBACtion CustomCell.
, , , didSelectRowAtIndexPath, ( , ).
? , , " " , .
!