2012-07-30 94 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]; 
    } 
相關問題