0

I lost a bit nerves on this case. I have UIView with few images as buttons. I would like to insert it with insertRowsAtIndexPaths: I have no idea how to start with that, and I really searched every site on google. I even found something that works like a charm ( http://jackkwok.github.io/JKExpandTableView/ ) but I still cannot make it right. Here is my didSelectRowAtIndexPath method:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    int selectedRow = indexPath.row;
    NSLog(@"touch on row %d", selectedRow);


    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    PrototypeCell *prototypeCell =(PrototypeCell *)[tableView cellForRowAtIndexPath:indexPath];
    if (prototypeCell.stretched == NO){
    [UIView animateWithDuration:1 animations:^{
        prototypeCell.View.frame = CGRectMake(0, 0, 320, 120);}
                     completion: nil];
        prototypeCell.stretched = YES;}
    else {
        [UIView animateWithDuration:1 animations:^{
            prototypeCell.View.frame = CGRectMake(0, 0, 15, 120);}
                         completion: nil];
        prototypeCell.stretched = NO;
    }

    // Start a new core animation transaction
    [CATransaction begin];
    // Set a completion block for the animation
    [CATransaction setCompletionBlock:^{
//        
//         Update the data model to add a new section
//        [_data addObject:[DetailView init] alloc];
        NSInteger item = self.thingList.count-1;
        // Animate the new section apperance
        [tableView beginUpdates];
        [tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForItem:item inSection:0], nil] withRowAnimation:UITableViewRowAnimationFade];
        NSLog(@"Array is:  %@", _data);
//        [tableView endUpdates];


    }];

    [CATransaction commit];


}

My head is already numb from that problem. I cannot even understand basic inserting, how I write what I would like to insert here? Any Help appreciated!

Drwalcore
  • 161
  • 1
  • 13
  • This seems to have been covered in http://stackoverflow.com/questions/6943470/how-to-properly-use-insertrowsatindexpaths – ekscrypto Nov 10 '15 at 15:20
  • ok basic inserting is covered in this topic, thanks! But what about the rest - inserting view into cell? – Drwalcore Nov 10 '15 at 15:23
  • To clarify, your intent is to have a row, that when tapped expands to display buttons? – ekscrypto Nov 10 '15 at 15:28
  • Row, yes. And when I tap on it, under this tapped row, UIView with buttons will be showed - and other rows under this UIView will slide down, and will not be covered with it. – Drwalcore Nov 10 '15 at 15:30
  • This may be of use then: http://stackoverflow.com/questions/3069339/how-to-dynamically-resize-uitableviewcell-height – ekscrypto Nov 10 '15 at 15:31
  • Basically, what you want is to change the height of the cell, and tell the tableview that the cell needs to be adjusted. Then you make sure your cell itself has the buttons as subviews – ekscrypto Nov 10 '15 at 15:31

1 Answers1

1

Based on your described intent, I'm not entirely sure you need or want to insert table rows. It looks like what you are trying to achieve is to simply expand the height of a given row to reveal some extra buttons when that row is selected.

Changing the height of row is covered How to dynamically resize UITableViewCell height

Essentially you can have your PrototypeCell have some extra content (the buttons) that is usually clipped. When the view is selected, you simply change the height to make sure all of the buttons would be visible and you indicate to the tableview to reload the row that was selected.

Should you need to insert rows, this was covered in how to properly use insertRowsAtIndexPaths?

Good luck!

Community
  • 1
  • 1
ekscrypto
  • 3,718
  • 1
  • 24
  • 38
  • It works like a charm. Instead `insertRowAtIndexPaths` i resized Cell height Dynamically! Thanks a lot! I didn't even know about this method. Thanks! Now I am issuing propely showed views after click etc. but I think I can do it on my own. – Drwalcore Nov 12 '15 at 13:56