使用ContentView

时间:2015-11-10 15:15:47

标签: ios objective-c uitableview uiview

我对这个案子有点紧张。我有UIView几个图像作为按钮。我想用insertRowsAtIndexPaths:插入它 我不知道如何开始,我真的搜索谷歌上的每个网站。我甚至发现了一些像魅力(http://jackkwok.github.io/JKExpandTableView/)的东西,但我仍然无法做到正确。 这是我的didSelectRowAtIndexPath方法:

-(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];


}

我的头已经麻木了。我甚至不能理解基本插入,我怎么写我想插入的内容? 任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

根据您描述的意图,我不完全确定您是否需要或想要插入表格行。看起来你想要实现的只是扩展给定行的高度,以便在选择该行时显示一些额外的按钮。

更改行的高度How to dynamically resize UITableViewCell height

基本上你可以让你的PrototypeCell有一些额外的内容(按钮)通常被剪裁。选择视图后,只需更改高度以确保所有按钮都可见,并指示tableview重新加载所选行。

如果您需要插入行,请参阅how to properly use insertRowsAtIndexPaths?

祝你好运!