2012-07-30 32 views
2

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

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

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

回答

0

把视频和图像在一个UIView并将它们添加到您的细胞一样,如果单元格的高度是50,加上他们在51和写入

yourView.hidden=YES; 
[email protected]"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; 
     } 
    } 

希望这有助于!

+0

我解决了这一..我会回答它。 – Pallavi 2012-07-30 11:26:21

+0

你应该至少给回答者的辛勤工作+1,并接受你的答案作为答案..如果你认为这是正确的.. – 2012-07-30 11:42:28

0

添加以下代码在细胞“的cellForRowAtIndexPath:”

if([self cellIsSelected:indexPath]) 
    { 
     [cellButton setImage:[UIImage imageNamed:plusImageName] forState:UIControlStateNormal]; 
     [email protected]"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]; 
    } 
相关问题