Setting up a UITableView cell at runtime

I have subclassed UITableViewCell. What I want to have is when I click on a cell, I added a UIView at the bottom of the cell and adjusted the cell height accordingly. Here is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   
MyCell* cell = (MyCell *) [self.table cellForRowAtIndexPath:indexPath]; 
UIView * options = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height - 27, cell.frame.size.width, 27)];
UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[options addSubview:button1];
UIButton* button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[options addSubview:button2];
UIButton* button3 = [UIButton buttonWithType:UIButtonTypeCustom];
[options addSubview:button3];
//did some layout calculation here to position the button
[cell addSubview:options];
}

Here is a video that illustrates the problem

I also tried changing the accessView of my cell from my custom UIButton to a regular UITableViewCellAccessoryDisclosure, but it did not work

MyCell * cell = (MyCell *)[self.table cellForRowAtIndexPath:temp];
     [cell.accessoryView removeFromSuperview];
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

If you are interested in what I am trying to do, I am trying to create a tweetbot uitableviewcell where you click on a cell / row and it presents you with other options (retweets, etc.), and also it was shown animated.

+3
source share
2 answers

, , . UITableViewCell, - (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath

[tableView beginUpdates];
[tableView endUpdates];
+2

insertRowsAtIndexPaths:withRowAnimation:   

deleteRowsAtIndexPaths:withRowAnimation: 

.

0

All Articles