如果表格单元格将展开,如何显示图像/视频?

时间:2012-07-30 06:04:08

标签: iphone uitableview

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

enter image description here

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

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

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

2 个答案:

答案 0 :(得分: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;
        }
    }

希望这会有所帮助!!

答案 1 :(得分: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]; 
    }