2

我已经创建了表格,我想在单击“+”按钮时在其中展开单元格,并在其中添加图像和视频。有时它需要增加特定的单元格高度,然后显示视频,“+”号将转换为“-”。

在此处输入图像描述

现在我添加了代码来扩展单元格,如下所示

-(void)cellButtonOneSelected
{
    // Deselect cell
[safetChecklistsTableView deselectRowAtIndexPath:selectedIndexPath1 animated:TRUE];

// Toggle 'selected' state
BOOL isSelected = ![self cellIsSelected:selectedIndexPath1];

// Store cell 'selected' state keyed on indexPath
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:selectedIndexPath1];    

// This is where magic happens...
[safetChecklistsTableView beginUpdates];
[safetChecklistsTableView endUpdates];
}

现在如何在其中显示/添加视频或图像?

4

2 回答 2

0

在单元格 'cellForRowAtIndexPath:' 中添加以下代码

 if([self cellIsSelected:indexPath])
    {
        [cellButton setImage:[UIImage imageNamed:plusImageName] forState:UIControlStateNormal];
        cellSubLabel.text=@"Close";

      if (indexPath==selectedIndexPath) {
        UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
        imageView.frame = (CGRect){170,80,130,80};
        [tableCell addSubview:imageView];
     }
   }
    else
    {
        [cellButton setImage:[UIImage imageNamed:minusImageName] forState:UIControlStateNormal]; 
    }
于 2012-07-30T11:34:21.597 回答
0

将视频和图像放在uiview中并将它们添加到您的单元格中,就像单元格的高度为50一样,将它们添加到51。然后写

yourView.hidden=YES; 
yourView.tag=@"your Tag"

按下此添加按钮时,调用以下循环:

for (int section = 0, sectionCount = _iTableView.numberOfSections; section < sectionCount; ++section) {
        for (int row = 0, rowCount = [_iTableView numberOfRowsInSection:section]; row < rowCount; ++row) {
            UITableViewCell *cell = [_iTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
            UIView *view=(UIView*)[cell.contentView viewWithTag:@"Your Tag"];
            view.hidden=NO;
        }
    }

希望这可以帮助!!

于 2012-07-30T09:06:31.263 回答